Skip to content

Comments

support client reconnection after transport disruption#16

Open
kitknox wants to merge 4 commits intotrzsz:mainfrom
kitknox:clientreconnect
Open

support client reconnection after transport disruption#16
kitknox wants to merge 4 commits intotrzsz:mainfrom
kitknox:clientreconnect

Conversation

@kitknox
Copy link

@kitknox kitknox commented Feb 6, 2026

Allow clients to reconnect to a running tsshd by establishing an entirely new KCP or QUIC transport after the original connection and all its state have been lost. This enables recovery from network roaming, sleep/wake, and mobile use cases where the OS may terminate and relaunch the client app (e.g. Rootshell terminal on iOS).

  • Resume existing sessions by reattaching I/O to the new transport
  • Buffer stdout during handoff to prevent output loss
  • Replace bus stream on reconnect with identity-guarded cleanup
  • Gate non-bus streams on bus ownership to prevent hijacking
  • Track discard markers per-session to avoid cross-session interference
  • Accept transport connections in a loop to support reconnection
  • Add mutex protection to onExitFuncs and use context-based keepalive
  • Add tests for reconnection scenarios

Allow clients to reconnect to a running tsshd by establishing an
entirely new KCP or QUIC transport after the original connection and
all its state have been lost. This enables recovery from network
roaming, sleep/wake, and mobile use cases where the OS may terminate
and relaunch the client app (e.g. Rootshell terminal on iOS).

- Resume existing sessions by reattaching I/O to the new transport
- Buffer stdout during handoff to prevent output loss
- Replace bus stream on reconnect with identity-guarded cleanup
- Gate non-bus streams on bus ownership to prevent hijacking
- Track discard markers per-session to avoid cross-session interference
- Accept transport connections in a loop to support reconnection
- Add mutex protection to onExitFuncs and use context-based keepalive
- Add tests for reconnection scenarios
Replace globalProtoServer.getUdpForwarder() with getActiveBusForwarder()
since the reconnection model tracks forwarders per-connection via the
active bus, not globally on the server. Update tests for new listenKCP
signature and initialize globalServerProxy in bus forwarder test.
@lonnywong
Copy link
Member

@kitknox Thanks a lot for the PR and for taking the time to work on this! It’s very helpful and gives me a good starting point.

I’d like to spend some time thinking about a cleaner refactor overall, so I may take a slightly different approach for the final implementation.

I’ve just started my vacation, so it may take a few weeks before I can work on this properly.

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