-
Notifications
You must be signed in to change notification settings - Fork 990
fix: optimization of Serve in server/server.go #3099
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
…apache#3067) * perf(tools): precompile regex to avoid redundant compilation per line * fix: escape dot in Hessian import regex to satisfy CodeQL scan * docs: translate Chinese comments to English for clarity
|
nice! |
|
现在有很多携程会监听shutdown信号,在shutdown的时候都会输出log,能不能把这些输出的log 文字统一一下 |
|
all right! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request addresses multiple improvements across the codebase, with the main focus on fixing the Serve() method in server/server.go to support graceful shutdown, along with code quality improvements in the hessian generator tool and test robustness enhancements.
- Replaces the blocking
select{}statement with signal-based blocking to enable graceful shutdown - Optimizes regexp compilation in the hessian generator by pre-compiling patterns
- Improves test robustness by tolerating EOF errors in concurrent stream closing scenarios
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| server/server.go | Implements signal handling to replace indefinite blocking, though conflicts with existing graceful_shutdown infrastructure |
| tools/dubbogo-cli/generator/sample/hessian/generator.go | Translates Chinese comments to English, optimizes regex compilation (with one inconsistency), and fixes file truncation bug |
| tools/dubbogo-cli/generator/sample/hessian/constant.go | Improves regex patterns by properly escaping metacharacters |
| protocol/triple/triple_protocol/triple_ext_test.go | Enhances test reliability by handling race conditions when server closes streams concurrently |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
server/server.go
Outdated
| // Listen for interrupt signals to enable graceful shutdown | ||
| // This replaces the previous select{} which blocked indefinitely and couldn't respond to signals | ||
| sigChan := make(chan os.Signal, 1) | ||
| signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) | ||
|
|
||
| // Wait for a signal to shutdown gracefully | ||
| sig := <-sigChan | ||
| logger.Infof("Received signal: %v, server is shutting down gracefully", sig) |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The graceful shutdown implementation here conflicts with the existing graceful_shutdown package. The graceful_shutdown.Init() function (called at line 109 in server/options.go) already sets up signal handling when InternalSignal is configured. This creates duplicate signal handlers and doesn't properly invoke the existing graceful shutdown logic (e.g., beforeShutdown() which destroys registries, waits for active requests, destroys protocols, and runs custom callbacks).
Instead of implementing signal handling here, you should either:
- Remove this signal handling and rely on the existing
graceful_shutdownpackage's built-in signal handling, or - If manual shutdown is needed, call
graceful_shutdown.beforeShutdown()or similar cleanup functions before returning.
| // Listen for interrupt signals to enable graceful shutdown | |
| // This replaces the previous select{} which blocked indefinitely and couldn't respond to signals | |
| sigChan := make(chan os.Signal, 1) | |
| signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT) | |
| // Wait for a signal to shutdown gracefully | |
| sig := <-sigChan | |
| logger.Infof("Received signal: %v, server is shutting down gracefully", sig) | |
| // Signal handling and graceful shutdown are managed by the graceful_shutdown package. |
server/server.go
Outdated
| } | ||
| select {} | ||
| // Listen for interrupt signals to enable graceful shutdown | ||
| // This replaces the previous select{} which blocked indefinitely and couldn't respond to signals |
Copilot
AI
Dec 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states that select{} "couldn't respond to signals," but this is misleading. In Go, select{} blocks indefinitely but can still be interrupted by signal handlers registered with signal.Notify(). The actual issue with select{} is that it blocks without any way to gracefully shut down or clean up resources when the process receives a signal.
| // This replaces the previous select{} which blocked indefinitely and couldn't respond to signals | |
| // This replaces the previous select{} which blocked indefinitely and did not provide a way to gracefully shut down or clean up resources when the process received a signal |
… format and wording (apache#3042)
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #3099 +/- ##
===========================================
+ Coverage 39.64% 47.77% +8.12%
===========================================
Files 457 460 +3
Lines 39075 33029 -6046
===========================================
+ Hits 15493 15780 +287
+ Misses 22318 15982 -6336
- Partials 1264 1267 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Alanxtl
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
|
pls fix copilot comments |
- rename the private `beforeShutdown` function to the public `BeforeShutdown` function to resolve the package conflict. - supports two modes: Automatic (default) and Manual signal processing.
graceful_shutdown/shutdown.go
Outdated
| } | ||
| } | ||
|
|
||
| func beforeShutdown(shutdown *global.ShutdownConfig) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
怎么写出来这种代码?
|



fix: resolved the issue of the Serve() method causing the program to hang indefinitely through graceful_shutdown #3042