Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

heartbeat thread is sometimes not terminated upon client closing #154

Open
spew opened this issue Nov 4, 2014 · 10 comments
Open

heartbeat thread is sometimes not terminated upon client closing #154

spew opened this issue Nov 4, 2014 · 10 comments
Milestone

Comments

@spew
Copy link

spew commented Nov 4, 2014

I am running into a frequent issue where the heartbeat thread does not get interrupted properly when close my SSHClient object. This happens often when the sshClient.connect is refused (I have a retry mechanism that retries this up to 20 times with fixed interval 10 second sleep). This leads to my application not exiting. Let me know if more information is needed -- I could attempt to write an isolated program to reproduce the issue.

If I had to guess it might be some sort of deadlock with the writeLock in TransportImpl as the Heartbeater needs to obtain that lock in its loop when it does a write(...)

@hierynomus
Copy link
Owner

For these kind of issues I would definitely welcome an isolated testcase which reproduces this behaviour. I you could supply one, I'm more than happy to fix this.

@hierynomus
Copy link
Owner

@spew I've changed a few things in the heartbeat mechanism for 0.11.0. Could you retry and see if this still happens, and else give me a small program that shows the problem?

Thx!

@spew
Copy link
Author

spew commented Mar 27, 2015

Updating to 0.11.0 will report if/when we see this or close in a month or two if we don't.

@hierynomus
Copy link
Owner

Great, let me know!

@ksumit
Copy link

ksumit commented Apr 27, 2015

We hit this issue again, please see the stacktrace below:

Caused by: net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
    at net.schmizz.sshj.SSHClient.auth(SSHClient.java:217)
    at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:316)
    at net.schmizz.sshj.SSHClient.authPublickey(SSHClient.java:365)

Caused by: net.schmizz.sshj.userauth.UserAuthException: Timeout expired
    at net.schmizz.sshj.userauth.UserAuthException$1.chain(UserAuthException.java:33)
    at net.schmizz.sshj.userauth.UserAuthException$1.chain(UserAuthException.java:26)
    at net.schmizz.concurrent.Promise.retrieve(Promise.java:139)
    at net.schmizz.sshj.userauth.UserAuthImpl.authenticate(UserAuthImpl.java:69)
    at net.schmizz.sshj.SSHClient.auth(SSHClient.java:211)
    ... 15 more
Caused by: java.util.concurrent.TimeoutException: Timeout expired
    ... 18 more

@hierynomus hierynomus added this to the 1.0.0 milestone Jun 17, 2015
@lukelast
Copy link

I've also seen this issue where I ended up with 100's of heartbeater threads that leaked. The threads would also prevent a lot of garbage from being collected.

I solved this problem by using a scheduled executor instead. I'm currently Integrating my changes of the heartbeat functionality to my fork and hopefully the will be accepted if it solves the problem.

@mdwn
Copy link

mdwn commented Feb 22, 2017

I'm seeing this as well when auth fails -- basically, trying to connect to a non-existent host with a public key. We've got a wrapper around sshj, but adding in a client.getConnection().getKeepAlive().interrupt() when trying to close the client seems to kill the threads here.

@mbrucco
Copy link

mbrucco commented Sep 3, 2020

It happens when an host is unreachable with username and password too

@exceptionfactory
Copy link
Contributor

This issue should be resolved with updates in PR #752.

@spew
Copy link
Author

spew commented Jan 5, 2022

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants