Menu

#37 "java.net.SocketException: Socket is closed" in next Session.connect()

v1.0 (example)
open
nobody
None
2
2019-06-19
2019-06-13
dgu
No

Hello!

I've been using Jsch 0.1.54.

Here are the steps:

1- session.connect() --> works
2- session.disconnect() --> works
3- session.connect() --> "java.net.SocketException: Socket is closed"

are subsequet connect calls not supported in Jsch ?

Thanks in advance!

Discussion

  • dgu

    dgu - 2019-06-14

    Hello!

    I found a problem in my socket factory that It was trying to reuse socket closed by JSch.

    Here are the results of my test cases:

    With socket factory:

    1- session.connect() --> works
    2- session.disconnect() --> works
    immediately after disconnect
    3- session.connect() --> "java.net.ConnectException: Cannot assign requested address"
    1 minute later:
    4- session.connect() --> "com.jcraft.jsch.JSchException: Packet corrupt"

    I'm not sure; but, it looks JSch can not handle disconnect properly and I got " Cannot assign requested address" message.

    Without socket factory:

    1- session.connect() --> works
    2- session.disconnect() --> works
    3- session.connect() --> "com.jcraft.jsch.JSchException: Packet corrupt"

    It still looks that reconnecting to same Session is not supported with socket factory and without socket factory.

    Workaround:

    Create a new Session instance for each connection.

     
  • dgu

    dgu - 2019-06-14

    Th above test cases are done after I fixed my socket factory.

     
  • dgu

    dgu - 2019-06-19

    Even if I create new Session instance in each connection "java.net.ConnectException: Cannot assign requested address" happened again. It is a problem in my socket factory.

    The real problem is that if Session instance is reconnected then "com.jcraft.jsch.JSchException: Packet corrupt" happens.

    Workaround:

    Create a new Session instance for each connection.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.