fix(gonet): avoid shutdown timeout without active connections - #1985
Open
lmsn-kang wants to merge 1 commit into
Open
fix(gonet): avoid shutdown timeout without active connections#1985lmsn-kang wants to merge 1 commit into
lmsn-kang wants to merge 1 commit into
Conversation
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.
What type of PR is this?
fix
Check the PR title.
<type>(optional scope): <description>(Optional) Translate the PR title into Chinese.
fix(gonet): 避免无活动连接时 Shutdown 错误超时
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en:
gonet.transServer.Shutdowncurrently checks the active connection count only when its fixed 100 ms ticker fires. If there are no active connections andExitWaitTimeis shorter than 100 ms, the context deadline fires first andShutdownincorrectly returnscontext.DeadlineExceeded. Even with the default timeout, an idle server unnecessarily waits for the first ticker.This change checks the connection count immediately after the existing graceful-shutdown notification. Active connections still use the existing ticker and context deadline behavior.
A regression test covers an idle server with a 10 ms exit wait time.
zh(optional):
gonet.transServer.Shutdown原本只在固定的 100 ms ticker 触发时检查活动连接数。当没有活动连接且ExitWaitTime小于 100 ms 时,context 会先超时,导致Shutdown错误返回context.DeadlineExceeded。本修改在原有优雅关闭通知之后立即检查一次连接数;存在活动连接时仍沿用原有轮询和超时逻辑。Tests:
go test ./pkg/remote/trans/gonet -count=20go test ./server ./server/genericserver -count=1go vet ./pkg/remote/trans/gonetManual TCP lifecycle test on Windows using a real Gonet listener and client connection:
conn=0,ExitWaitTime=10ms: upstream returnedcontext deadline exceededafter 10.752 ms; this patch returnednilimmediately.conn=1,ExitWaitTime=500ms: upstream returnednilafter 100.374 ms; this patch closed the connection and returnednilimmediately.conn=1,ExitWaitTime=30ms: both versions correctly returnedcontext deadline exceededafter about 30 ms.(Optional) Which issue(s) this PR fixes:
N/A
(optional) The PR that updates user documentation:
N/A