Skip to content

Conversation

@y138g
Copy link

@y138g y138g commented Dec 2, 2025

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

zbchi and others added 3 commits October 28, 2025 20:29
…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
@97ZQ
Copy link
Contributor

97ZQ commented Dec 3, 2025

nice!

@Alanxtl
Copy link
Contributor

Alanxtl commented Dec 4, 2025

现在有很多携程会监听shutdown信号,在shutdown的时候都会输出log,能不能把这些输出的log 文字统一一下

2025-12-04 10:47:38   INFO    graceful_shutdown/shutdown.go:90    get signal interrupt, applicationConfig will shutdown.
2025-12-04 10:47:38     INFO    server/server.go:226    Received signal: interrupt, server is shutting down gracefully
2025-12-04 10:47:38     INFO    graceful_shutdown/shutdown.go:148   Graceful shutdown --- Destroy all registriesConfig. 
2025-12-04 10:47:38     INFO    cmd/server.go:132       Received signal: interrupt, shutting down...

@y138g
Copy link
Author

y138g commented Dec 4, 2025

all right!

Copy link
Contributor

Copilot AI left a 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
Comment on lines 219 to 226
// 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)
Copy link

Copilot AI Dec 4, 2025

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:

  1. Remove this signal handling and rely on the existing graceful_shutdown package's built-in signal handling, or
  2. If manual shutdown is needed, call graceful_shutdown.beforeShutdown() or similar cleanup functions before returning.
Suggested change
// 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.

Copilot uses AI. Check for mistakes.
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
Copy link

Copilot AI Dec 4, 2025

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.

Suggested change
// 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

Copilot uses AI. Check for mistakes.
@Alanxtl Alanxtl added the enhancement New feature or request label Dec 5, 2025
@Alanxtl Alanxtl linked an issue Dec 8, 2025 that may be closed by this pull request
1 task
@codecov-commenter
Copy link

codecov-commenter commented Dec 11, 2025

Codecov Report

❌ Patch coverage is 2.94118% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.77%. Comparing base (1a7b169) to head (e5b18db).
⚠️ Report is 66 commits behind head on develop.

Files with missing lines Patch % Lines
server/server.go 0.00% 16 Missing ⚠️
graceful_shutdown/shutdown.go 6.25% 15 Missing ⚠️
config/graceful_shutdown.go 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@Alanxtl Alanxtl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@Alanxtl
Copy link
Contributor

Alanxtl commented Dec 11, 2025

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.
}
}

func beforeShutdown(shutdown *global.ShutdownConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

怎么写出来这种代码?

@AlexStocks AlexStocks added 3.3.2 version 3.3.2 and removed 3.3.1 labels Dec 18, 2025
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.3.2 version 3.3.2 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[提案] server/server.go中Serve优化

6 participants