[jcifs] java.io.IOException: Failed to establish session

M. D. moder at abv.bg
Tue Mar 17 05:52:17 MDT 2015


 Hello,

I think I found the cause for the 

jcifs.util.transport.TransportException 
java.io.IOException: Failed to establish session with 0.0.0.0<00>/192.168.0.110 
at jcifs.smb.SmbTransport.ssn139(SmbTransport.java:284) 
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:294) 
at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:367) 
at jcifs.util.transport.Transport.run(Transport.java:241) 
at java.lang.Thread.run(Thread.java:856) 
at jcifs.util.transport.Transport.run(Transport.java:258) 

exception which causes jcifs to be unable to recover from loss of connectivity/networking issues under heavy load.

Imagine the following scenario:
1. Unplug the network cable.
2. jcifs.smb.SmbTransport#doConnect() -> the first negotiate() is called with port 445
3. jcifs.smb.SmbTransport#negotiate() fails on port 445 with ConnectException/NoRouteToHostException
4. Plug the cable back
5. The ConnectException/NoRouteToHostException is catched back in the SmbTransport#doConnect() method. A second negotiate() attempt is made over port 139.
6. The SmbTransport#ssn139() socket.connect is successful because the connectivity is restored. In some rare cases (I still haven't figured out why) the remote host can reply with NetBT session response containing error code CALLED_NOT_PRESENT or NOT_LISTENING_CALLED.
7. The socket is closed and the following exception is thrown:
jcifs.util.transport.TransportException 
java.io.IOException: Failed to establish session with 0.0.0.0<00>/192.168.0.110 
at jcifs.smb.SmbTransport.ssn139(SmbTransport.java:284) 
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:294) 
at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:367) 
at jcifs.util.transport.Transport.run(Transport.java:241) 
at java.lang.Thread.run(Thread.java:856) 
at jcifs.util.transport.Transport.run(Transport.java:258) 

8. The transport gets disconnected.
9. Transport#connect() is executed by some client. A new transport thread is started that does doConnect()
10. The doConnect() first attempts negotiate() on port 139. But it fails again with CALLED_NOT_PRESENT
11. The following exception is thrown again:
jcifs.util.transport.TransportException 
java.io.IOException: Failed to establish session with 0.0.0.0<00>/192.168.0.110 
at jcifs.smb.SmbTransport.ssn139(SmbTransport.java:284) 
at jcifs.smb.SmbTransport.negotiate(SmbTransport.java:294) 
at jcifs.smb.SmbTransport.doConnect(SmbTransport.java:367) 
at jcifs.util.transport.Transport.run(Transport.java:241) 
at java.lang.Thread.run(Thread.java:856) 
at jcifs.util.transport.Transport.run(Transport.java:258) 

12. Since this is IOException and not ConnectException/NoRouteToHostException the doConnect() never catches this exception and the port is not restored back to 445.
13. Steps 8-12 are repeated endlessly until the remote server stop replying with CALLED_NOT_PRESENT or the ssn139() socket.connect() fails with ConnectException or NoRouteToHostException in which case the port is set back to 445.


Mike, what do you think? Imho you should add a line in SmbTransport#ssn139():

switch (errorCode) {
                        case NbtException.CALLED_NOT_PRESENT:
                        case NbtException.NOT_LISTENING_CALLED:
                            socket.close();
                            port = 445; // set back port 445
                            break;


Best regards,
M.D.


 >-------- Оригинално писмо --------
 >От:   M. D.  
 >Относно: java.io.IOException: Failed to establish session
 >До: jcifs at lists.samba.org, adam.morgan at Q1Labs.com, MSedliak at softip.sk, 
	naveenmah at gmail.com
 >Изпратено на: Четвъртък, 2015, Март 12 11:12:00 EET
 >
 >
 > Hello Adam, Mike, Everyone
 >

 >
Have you had any luck discovering the root cause for this issue?
 >

 >
I posted a few months ago on the mailing list. One of our customers suffers from exactly the same issue but we're currently not able to reproduce it on our side.
 >
https://lists.samba.org/archive/jcifs/2014-October/010188.html
 >
The same issue reported a long time ago by other users: 
 >
http://samba.2283325.n4.nabble.com/Failed-to-establish-session-td2512348.html#a2512349
 >
http://samba.2283325.n4.nabble.com/IOException-at-ssn139-access-print-server-td4643959.html
 >

 >
I just dug up this thread and I see that you suffered from the same thing and you were able to debug it locally. 
 >
I know it was a long time ago but do you by any chance remember what was the OS of the server machine? Did you use NetBIOS with alternative names + Windows Server 2003 for the server? If that's the case then it might be related to:
 >
http://support.microsoft.com/kb/940684
 >

 >
Also, do you remember any details about your environment in general? Any tips on how to reproduce that will be appreciated!
 >

 >
Best regards,
 >
M.D.
 >

 >


More information about the jCIFS mailing list