Skip to content

JSch SSH tunnel implementation robustness improvements #2423

Closed

Description

@richturner

The JSch SSH tunnel implementation is not robust, it has no reconnect logic and it doesn't provide callbacks for connection issues.

See the following log showing tunnel socket failures:

root@013a466:~# balena logs -t 063 2>&1 | grep "Caught an exception"
2026-01-16T14:24:18.887695000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T14:33:25.701403000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T14:46:57.166493000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T15:05:06.878513000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T15:20:36.394997000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T15:35:02.652126000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T15:50:37.032995000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T15:54:41.633763000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T16:07:09.490565000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed
2026-01-16T16:25:01.597533000Z INFO    [Connect thread staging.v..sion] com.jcraft.jsch.JSch                     : Caught an exception, leaving main loop due to Socket closed

Two steps required to improve this:

  • Implement callbacks for underlying connection changes
  • Implement reconnection logic

Activity

  1. richturner commented on Jan 16, 2026

    @richturner
    MemberAuthor

    Let's look at moving to https://github.com/hierynomus/sshj

  2. ebariaux commented on Jan 19, 2026

    @ebariaux
    Contributor

    There's also https://github.com/sshtools/maverick-synergy but it has a commercial license part (https://jadaptive.com/java-ssh-library/), not sure how that would impact us.
    And never used it.

  3. richturner commented on Jan 19, 2026

    @richturner
    MemberAuthor

    Think I will try the Apache MINA SSHD client for more widespread support and hopefully less risk of becoming unsupported, just don't know how heavy this library is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions