RestComm / jain-sip

Disclaimer: This repository is a git-svn mirror of the project found at http://java.net/projects/jsip whose original repository is developed collaboratively by the Advanced Networking Technologies Division at the National Institute of Standards and Technology (NIST) - an agency of the United States Department of Commerce and by a community of individual and enterprise contributors. TeleStax, Inc. will perform some productization work, new features experimentation branches, etc for its TelScale jSIP product that doesn't concern the community from the main repository hence this git repository.
http://www.restcomm.com/
144 stars 152 forks source link

Possible Fix : Connected flag in NIOHandler.java > openOutgoingConnection is not updated correctly #188

Open adkhadilkar opened 5 years ago

adkhadilkar commented 5 years ago

First thanks for making this great library for SIP communication !!

While using the Jain SIP library for SIP over Websocket, I found one issue in NIOHandler.java file in openOutgoingConnection method. Inside the openOutgoingConnection there is connected flag (Line 257) defined which wasn't updated in the same method. As we are checking the value in finally(Line 369/371) everytime it is creating new socket.

Ideally from my understanding we need to set the connected to true once we create the socket. before/after putSocket(key, clientSock); line (305/356)

albertpv commented 5 years ago

Fully agree with the suggested change by @adkhadilkar
I was having situation where the TCP connection between SIP Proxy and B2BUA is closed sometimes and the behaviour when using NioTcpMessageProcessor was working randomly. Instead using the regular TCPMessageProcessor it was working fine,.

I added the lines suggested then socket is recreated adequately and the issue i was having is corrected ( i guess previously it was closed in the finally clause :-( )

--- a/src/gov/nist/javax/sip/stack/NIOHandler.java
+++ b/src/gov/nist/javax/sip/stack/NIOHandler.java
@@ -303,6 +303,7 @@ public class NIOHandler {
                                                 receiverAddress + " " + contactPort + " " + senderAddress);
                                     }
                                     putSocket(key, clientSock);
+                                   connected=true;
                                     break;
                             } else {
                                     break;
@@ -354,6 +355,7 @@ public class NIOHandler {
                             clientSock = messageProcessor.connect(new InetSocketAddress(receiverAddress, contactPort), 
                                     senderAddress, this.messageProcessor.sipStack.connTimeout);
                             putSocket(key, clientSock);
+                           connected=true;
                     } 

So i would agree with the reported issue.