Tear down SSH tunnel on abnormal client disconnect#3897
Merged
Conversation
`nrepl--ssh-tunnel-connect' spawns a separate `ssh' subprocess for port forwarding and stashes it on the client buffer's `nrepl-tunnel-buffer'. The orderly teardown path -- `cider-quit' -> `cider--close-connection' -- already kills the tunnel buffer. But the `nrepl-client-sentinel' path, which fires on abnormal client- process death (server crash, network drop, kill -9), only ran the disconnect hooks and the maybe-kill-server-buffer cleanup. Neither touches the tunnel, so the `ssh' subprocess kept running until Emacs itself exited. Add the tunnel cleanup to the sentinel, symmetric with the existing `nrepl--maybe-kill-server-buffer' call. Same layering: the transport sentinel owns transport-infrastructure cleanup.
ecc7303 to
3fa8f2d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Found during a wider audit of connection handling.
nrepl--ssh-tunnel-connectspawns a separatesshsubprocess for port forwarding and stashes it on the client buffer'snrepl-tunnel-buffer. The orderly teardown path --cider-quit→cider--close-connection-- already kills the tunnel buffer cleanly.But the
nrepl-client-sentinelpath, which fires on abnormal client-process death (server crash, network drop, the client process getting killed), only ran the disconnect hooks and thenrepl--maybe-kill-server-buffercleanup. Neither of those touches the tunnel, so thesshsubprocess kept running until Emacs itself exited. On macOS / Linux you'd see it viaps; on Windows it's worse sincetaskkillcleanup also doesn't reach it.Add the tunnel cleanup right next to the existing
nrepl--maybe-kill-server-buffercall in the sentinel, symmetric with how the server gets handled. Same layering: the transport sentinel owns transport-infrastructure cleanup.