Null exception within a Try block?

.NET library for SMPP protocol
Locked
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Null exception within a Try block?

Post by ishmell » Fri Mar 23, 2012 5:49 pm

I had an unexpected exception occur while running a compiled software application that uses the InetLab DLL v1.0.11.4. I decided to run the software from VB.NET 2008 to catch the exception "in the act" and found the exception occurring on the Submit method. The odd thing is that the Submit method in question is wrapped in a Try/Catch block; http://amal.net/caps/2012-03-23_10-33-37.png

Any idea why the Try block would not catch this?

Any idea why this would happen in the first place?
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Null exception within a Try block?

Post by alt » Fri Mar 23, 2012 8:12 pm

Could you show Stack Trace of this exception?

I suppose you run this code in Debug therefore this exception was displayed.
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Mon Mar 26, 2012 5:14 pm

I've been running the code in debug mode for days now and still the exception has not occurred. I believe it might have had something to do with the SMPP packet itself because the provider had some other issues that day that resulted in SMPP binds changing their default data_coding values and causing message encoding errors. Perhaps they also had corrupted SMPP packets on the line as well? I'm running a packet sniffer alongside the software running in debug mode. If the error happens again, I will post the stack trace output and packet data.
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Wed Mar 28, 2012 8:42 pm

I have not been able to regenerate the same error after days of running in debug mode. That is to be expected I guess as the production version was running for weeks before this error cropped up.

However, I saw the same type of error occur at the same exact place when I was stepping through the code so slowly that the TCP socket itself had disconnected due to the remote side not getting a response from an EnquireLink. I could not get a stack trace or do anything because the IDE also locked up and I had to kill the IDE process.

Perhaps this could be a socket related error, i.e. a message is getting ready to send out but the socket has unexpectedly disconnected just prior to sending? This is the debug console output for the process, which shows the TCP socket failing shortly before the null exception hitting; http://amal.net/caps/2012-03-27_11-23-18.png
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Fri May 04, 2012 5:14 pm

OK! It finally happened in my dev IDE and here are the results, though they are not very informative;

http://amal.net/caps/2012-05-04_10-06-37.png

http://amal.net/caps/2012-05-04_10-08-03.png

I'm still not sure why the try block is being ignored and the exception is halting execution. Any help would be greatly appreciated, as this is literally a show-stopper.
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Null exception within a Try block?

Post by alt » Thu May 10, 2012 5:59 pm

it looks like oSMPP object became null, and StackTrace doesn't point to library code. It is normal that visual studio had stopped inside try/catch in debug mode.
Do you apply multi-thread in your application? Maybe another thread recreated oSMPP object and you are trying to access disposed old object?
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Thu May 10, 2012 6:41 pm

This null exception happened in the compiled release version as well so halting execution in the try/catch block is not due to debug mode. Also, I don't recall any instance where the VS IDE would stop with an exception within a try/catch block unless there was a break point... it always follows error handling routines as expected, even in debug mode. Is your experience with VS different than mine?

The oSMPP object is created upon start of the application and is not disposed until the application is closed. The exception always happens at exactly the same point as well; the oSMPP.Submit method.
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Thu May 17, 2012 9:15 pm

Ok, so after researching how try/catch works, the problem MUST exist in the InetLab DLL... i.e. something in the InetLab code is not properly doing error catching and raising events, it's simply tripping on an exception, and the try/catch block in my VB.NET code is not able to handle errors in called code that do not properly catch and raise errors.

This appears to be a bug in the SMPP DLL.
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Null exception within a Try block?

Post by alt » Fri May 18, 2012 7:10 pm

Sorry ishmell, I'm not able to reproduce this problem, so until then i don't know what to fix in the library.

Anybody else having similar problem?
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Fri May 18, 2012 7:24 pm

I'm still trying to get a fresh network packet capture at the time of the exception, but I believe it has to do with a dead TCP socket on the transmit SMPP bind when we try to send out an MT message to a phone. Either that, or the TCP socket dies upon sending the message. The remote SMSC is having TCP resource and socket exhaustion issues on their end but has not indicated an ETA on a resolution.
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Null exception within a Try block?

Post by NickAskew » Thu Jun 07, 2012 2:33 pm

Hi Ishmel,

Is it possible that the last parameter you use for .PrepareSubmit could be Nothing/Null? The SMPP component may well be handling the exceptions internally and seeing null it then passes a null out which will then freak out the assignment [oRespList = ] meaning the SMPP exception will not fire. The screenshot is cut short so I can't see if you are attempting to handle any exceptions other than those raised via the SMPP component [Catch smppEx As Inetlab...], if you do not have a general exception handler below this and the [oRespList = ] assignment fails then it will throw the message you are seeing.

Cheers
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Thu Jun 07, 2012 6:45 pm

Hi Nick,

Thanks for responding. The relevant code is as follows;

oSubmitList = oSMPP.PrepareSubmit(SubmitMode.ShortMessage, Byte.Parse(sTON), Byte.Parse(sNPI), strFrom, Byte.Parse(dTON), Byte.Parse(dNPI), strTo, DataCodings.Latin1, oMsg.Body)

oRespList = oSMPP.Submit(oSubmitList) <= this is where the null exception occurs

I have confirmed that none of the values submitted to the PrepareSubmit method are null, so nothing on oSubmitList should be null going into the Submit method. This only crops up when there are network issues on the remote side that periodically cause issues with dropped TCP/IP connections, so I'm still thinking this issue is 1) somewhere in the DLL code, and 2) has to do with network issues during message submission.
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Null exception within a Try block?

Post by NickAskew » Thu Jun 07, 2012 11:28 pm

Hi,

I meant are you catching any other exception type, in the following code the exception handler will only catch the exception if it is of type SmppException.

Try
strFrom = oMsg.ChannelAddress
...
Catch smppEx As Inetlab.SMPP.common.SmppException
' Only exceptions of type SmppException will be caught by this exception handler.
End Try


The following code will also catch any other type of exception rather than freaking your app out.

Try
strFrom = oMsg.ChannelAddress
...
Catch smppEx As Inetlab.SMPP.common.SmppException
' This will throw if the exception type is SmppException
Catch ex As Exception
' This will throw for any other type of exception (rather than terminating your application)
' In here you can dump out the full exception trace and content of any local vars..
End Try


I managed to get your error by using the following code, this suggests that oRespList in your code is ending up as 'Nothing' for whatever reason:

Using oSMPP As New SmppClient
oSMPP.Connect("localhost", 7777)
oSMPP.Bind("alt", "alt")

Dim oSubmitList As List(Of Inetlab.SMPP.PDU.SubmitSm)
Dim oRespList As List(Of SubmitSmResp)

oSubmitList = Nothing
oRespList = oSMPP.Submit(oSubmitList) <-- This throws the NullReferenceException, not an SmppException.
End Using

Cheers
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
ishmell
Posts: 10
Joined: Wed Jan 25, 2012 1:29 am

Re: Null exception within a Try block?

Post by ishmell » Fri Jun 08, 2012 2:34 am

Nick,

Thanks for reminding a newb VB.NET programmer about catching different error types. I've added a Catch ex as Exception section to catch other types of exceptions, log them, and reschedule the message for sending. Hopefully in looking at the logs I will be able to determine more about what's causing the issue.

Likely oRespList is returning nothing due to network errors... the SMSC has confirmed with me that on the dates and times of the exceptions I had, they were having serious socket depletion issues on their side. They run both SMPP and HTTP transports for SMS messages on the same server and when their HTTP side gets busy they have socket availability issues. I have no idea why that would force an already connected SMPP connection down, it shouldn't... but that's what they are saying.

Thanks Nick!
NickAskew
Posts: 60
Joined: Tue Oct 07, 2008 1:35 pm

Re: Null exception within a Try block?

Post by NickAskew » Fri Jun 08, 2012 8:06 am

I certainly didn't want to teach you how to suck eggs!

..and I meant to write 'oSubmitList' is ending up as nothing.. :( it was a wee bit late!

Hope you get to the bottom of this.

Cheers
Nick
ProcessFlows UK Ltd
http://www.processflows.co.uk/
Locked