Skip to content

Add disconnect callback - #263

Open
LukaszMoskala wants to merge 2 commits into
gliderlabs:masterfrom
LukaszMoskala:master
Open

Add disconnect callback#263
LukaszMoskala wants to merge 2 commits into
gliderlabs:masterfrom
LukaszMoskala:master

Conversation

@LukaszMoskala

Copy link
Copy Markdown

Summary

Adds a DisconnectCallback, invoked when a connection dies after the SSH session was successfully established. This complements the existing ConnectionFailedCallback, which only covers connection failures.

Motivation

With SSH ControlMaster, multiple interactive sessions can share a single underlying SSH connection. When those sessions share resources tied to the connection, there needs to be a reliable hook to release them once the connection actually closes.

Releasing resources after the last interactive session closes isn't sufficient: with ControlMaster, the underlying SSH connection may still be alive and can still open new interactive sessions. DisconnectCallback fires specifically when the SSH connection itself ends, so cleanup only happens when no further sessions can be opened.

I have tested this and it works as expected.

Thank you for maintaining this library and have a nice day!

@LukaszMoskala

Copy link
Copy Markdown
Author

Interesting, tests pass on my local machine (go version go1.27.0-X:nodwarf5 linux/amd64) every time.

Can this test be re-run?

@blaubaer

blaubaer commented Sep 2, 2026

Copy link
Copy Markdown

Thanks a lot for proposing and implementing this, @LukaszMoskala — the DisconnectCallback fills an important gap in the connection lifecycle, especially for cases like SSH ControlMaster where resources are tied to the underlying connection rather than individual sessions.

We've ported your change to our maintained fork of gliderlabs/ssh here: engity-com/ssh-server-go#5

The original PR and your work are explicitly referenced there so that the origin and credit remain clear.

We're maintaining engity-com/ssh-server-go as a continuation of gliderlabs/ssh, since upstream development has unfortunately become rather quiet. Contributions like this are extremely valuable to us, so thank you for putting the work into designing and implementing this.

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

Successfully merging this pull request may close these issues.

2 participants