jain-sip icon indicating copy to clipboard operation
jain-sip copied to clipboard

Null Pointer on Socket Un-Connected

Open RichaChaudhary opened this issue 7 years ago • 1 comments

ISSUE - A null pointer exception is observed when socket is disconnected . Exception Trace - 2017-02-07 17:02:12,299 DEBUG [NioTcpMessageProcessor] (NioSelector-TCP-127.0.0.1/5062) After select 2017-02-07 17:02:12,299 DEBUG [NioTcpMessageProcessor] (NioSelector-TCP-127.0.0.1/5062) We got selkey sun.nio.ch.SelectionKeyImpl@36e7bca8 2017-02-07 17:02:12,299 DEBUG [NioTcpMessageProcessor] (NioSelector-TCP-127.0.0.1/5062) Read sun.nio.ch.SelectionKeyImpl@36e7bca8 2017-02-07 17:02:12,299 DEBUG [NioTcpMessageProcessor] (NioSelector-TCP-127.0.0.1/5062) Got something on nioTcpMessageChannel gov.nist.javax.sip.stack.NioTcpMessageChannel@1340aba7 socket java.nio.channels.SocketChannel[connected local=/127.0.0.1:5062 remote=/127.0.0.1:36460] 2017-02-07 17:02:12,299 DEBUG [NioTcpMessageChannel] (NioSelector-TCP-127.0.0.1/5062) NioTcpMessageChannel::readChannel 2017-02-07 17:02:12,300 DEBUG [NioTcpMessageChannel] (NioSelector-TCP-127.0.0.1/5062) Read 0 from socketChannel 2017-02-07 17:02:12,300 DEBUG [NioPipelineParser] (NioSelector-TCP-127.0.0.1/5062) new CallIDOrderingStructure added for message 2017-02-07 17:02:12,301 DEBUG [NioPipelineParser] (NioSelector-TCP-127.0.0.1/5062) Content Length parsed is 3192 2017-02-07 17:02:12,301 DEBUG [NioTcpMessageChannel] (NioSelector-TCP-127.0.0.1/5062) Closing socket java.io.IOException: The socket is giving us empty TCP packets. This is usually an indication we are stuck and it is better to disconnect., myAddress:myport null:0, remoteAddress:remotePort /127.0.0.1:36460 2017-02-07 17:02:12,301 DEBUG [NioTcpMessageChannel] (NioSelector-TCP-127.0.0.1/5062) Closing NioTcpMessageChannel gov.nist.javax.sip.stack.NioTcpMessageChannel@1340aba7 socketChannel = java.nio.channels.SocketChannel[connected local=/127.0.0.1:5062 remote=/127.0.0.1:36460] 2017-02-07 17:02:12,302 DEBUG [NIOHandler] (NioSelector-TCP-127.0.0.1/5062) Trying to remove cached socketChannel without keygov.nist.javax.sip.stack.NIOHandler@198f5858 socketChannel = java.nio.channels.SocketChannel[closed]

java.lang.NullPointerException at gov.nist.javax.sip.stack.ConnectionOrientedMessageChannel.processMessage(ConnectionOrientedMessageChannel.java:378) at gov.nist.javax.sip.parser.NioPipelineParser$Dispatch.run(NioPipelineParser.java:210) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) 2017-02-07 17:02:12,309 DEBUG [NioPipelineParser] (SIP-TCP-Core-PipelineThreadpool-2) CallIDOrderingStructure removed for message f73aac8a54a99abe9820724b25177796 2017-02-07 17:02:12,309 DEBUG [NioPipelineParser] (SIP-TCP-Core-PipelineThreadpool-2) releasing semaphore for message

STEPS TO REPLICATE USING SIPP

  1. Send a REGISTER request with invalid content-Length ( this would lead to IO Exception)
  2. End request by closing Socket Connection (ctrl+C)

OBSERVATION AND ANALYSIS It is seen that Null Pointer is observed in the Logs and the request parsing is terminated completely, with no trace of received request in the application logs. On Analysis, it is found that check for Socket connection is missing , leading to Null pointer Exception and no parsing of the request at all.

** FIX ** Include check for socket Connection to prevent Null pointer & allow request parsing gov.nist.javax.sip.stack.ConnectionOrientedMessageChannel

if (!this.isCached && mySock != null && mySock.isConnected()) { // self routing makes

ADVANTAGE GAINED The request is still processed, without Null pointer. The Socket Exception still occures, which is as expected as the Socket is closed

RichaChaudhary avatar Feb 28 '17 06:02 RichaChaudhary

hi @RichaChaudhary thanks for the comprehensive report.

Are you intereset on contirbuting with a patch? It seems you already have a good understanding of the situation, and potential solution....

jaimecasero avatar Mar 17 '17 14:03 jaimecasero