fix(net): Stop() 幂等化, 解决请求后 server 崩溃#38
Merged
Merged
Conversation
- stopOnce 替代 isClose 标志, 自然防止 double-Stop - 删除裸 recover() 与 close(msgChan)/close(msgBuffChan): worker 仍可能在 SendBuffMsg, close 触发 send on closed channel - ExitBuffChan 改非阻塞 send, 防止 Stop 在 buffer 已满时永阻塞 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe PR refactors ChangesIdempotent Connection Shutdown
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
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.
Summary
Connection.Stop()用sync.Once改成幂等, 替代isClose标志recover()与close(msgChan)/close(msgBuffChan): worker 仍可能在SendBuffMsg, close 会触发panic: send on closed channel(= "数据静态" 现象, server 处理首个请求后崩溃)ExitBuffChan在 Stop 内改为非阻塞 send, 防止 buffer 已满时永阻塞Background
原 Stop 末尾用
defer recover()吞掉 close 已关闭 channel 的 panic, 同时 close 了msgChan/msgBuffChan— 但 worker 还在通过SendBuffMsg往msgBuffChan写数据。删除 recover 后这个 panic 暴露, 修复方案是不 close 这两个 channel, 让它们随 Connection GC 即可。Test plan
go build ./...通过go vet ./network/...通过🤖 Generated with Claude Code
Summary by CodeRabbit