Fix zombie Input Reader thread when user changes password #169
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
A client was having a similar issue to previous #87 (using overthere 4.0.0 via rundeck winrm plugin, the problem exists in latest code as well).
The command they are executing changes the user's own password, and that causes the WinRM connection to be dropped immediately. It seems it leaves the overthere connection in a weird state, with the input reader thread still alive. After many executions of this, there were a lot of zombie "WinRM input reader for command..." threads in the JVM.
Here is the thread dump of the lingering threads:
I think the problem is in the finally clause of the
OverthereProcess.waitFor()
created in CifsWinRmConnection.java#startProcess:If the authentication is no longer valid, any call to winRmClient is going to throw an exception, but the finally clause calls
deleteShell
prior to stopping the thread for Stdin handling.The outputReaderThread calls
winRmClient.receiveOutput
, which I think causes an IO exception when the authentication is no longer valid. I.e. thewinrmClient.sendRequest
method will throw an exception due to authentication failure.At this point the outputReaderThread will finish, and the
.join()
call will complete.However the
finally
clause callswinRmClient.deleteShell()
, which also tries to dowinrmClient.sendRequest
, throwing another exception. ThecloseQuietly
is never performed, letting the thread reading the PipedInputStream stay alive.The client tested using this patch, and did not see any more zombie threads.
(Aside: The method
BaseOverthereConnection.execute
, does not provide any way to either use or close the stdin to the command, which may have been a workaround for us, and since it is not used it seems it probably should close it automatically.)