Fix: Automatic session reconnection for closed pipe errors#7
Open
AliRezaBeigy wants to merge 8 commits intoMygod:pluginfrom
Open
Fix: Automatic session reconnection for closed pipe errors#7AliRezaBeigy wants to merge 8 commits intoMygod:pluginfrom
AliRezaBeigy wants to merge 8 commits intoMygod:pluginfrom
Conversation
…le closed pipe errors
Author
|
^ @Mygod |
Owner
|
Any interest in this? ;) |
Author
|
@Mygod Thank you for the suggestion! |
Owner
|
Okay I've decided that I hate kcp so I'll just leave this PR as is and redirect you to slipstream. :) |
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.
Problem
After extended usage,
dnstt-clientwould fail with the error:This occurred when the smux session (or underlying KCP/Noise connection) became closed due to:
idleTimeoutconstant inmain.go:66and used asKeepAliveTimeoutin smux config at line 214)The original implementation created a single smux session at startup and never attempted to recreate it when it became invalid. Once the session closed, all subsequent stream opening attempts would fail permanently.
Solution
Implemented automatic session reconnection with the following improvements:
sessionManagerstruct that encapsulates the KCP connection, Noise channel, and smux session lifecycleChanges
Modified Files
dnstt-client/main.goKey Changes
New
sessionManagertype (lines 123-137):sync.RWMutexSession lifecycle methods:
newSessionManager(): Creates a new session managercreateSession(): Creates/recreates the full connection chain (KCP → Noise → smux)closeSession()/closeSessionLocked(): Cleanly closes all resourcesgetSession(): Thread-safe session retrieval with lazy initializationopenStream(): Opens a stream with automatic reconnection on failureEnhanced error detection (lines 286-290):
io.ErrClosedPipeio.EOFas a potential connection closure indicatorRefactored
handle()function:sessionManagerinstead of raw*smux.SessionopenStream()which handles reconnection automaticallyRefactored
run()function:sessionManagerinstance