Skip to content
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

fix: service group not working well when callback takes long time #4531

Merged
merged 1 commit into from
Jan 1, 2025

Conversation

kevwan
Copy link
Contributor

@kevwan kevwan commented Dec 29, 2024

fix #4261

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.58%. Comparing base (8690859) to head (72cb332).
Report is 194 commits behind head on master.

Additional details and impacted files
Files with missing lines Coverage Δ
core/proc/shutdown.go 75.51% <100.00%> (+1.59%) ⬆️
core/service/servicegroup.go 100.00% <100.00%> (ø)
gateway/server.go 72.59% <100.00%> (+3.68%) ⬆️

... and 7 files with indirect coverage changes

@kevwan kevwan force-pushed the feat/servicegroup branch 2 times, most recently from 6e754e7 to 1c44dbe Compare December 30, 2024 15:46
@kevwan kevwan requested a review from MarkJoyMa December 30, 2024 16:15
Copy link
Contributor Author

@kevwan kevwan left a comment

Choose a reason for hiding this comment

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

I'll help you review this pull request. Let me analyze the changes using the available tools.

Let me provide a thorough code review of the changes in PR #4531:

Key Changes:

  1. Improved Shutdown Handling (core/proc/shutdown.go):
  • Added explanatory comments about returning waitGroup.Wait
  • Good practice to improve code readability while maintaining functionality
  • The comment explains why an extra closure is created despite seeming redundant
  1. Service Group Improvements (core/service/servicegroup.go):
  • Enhanced parallel shutdown handling using threading.NewRoutineGroup()
  • Important fix for Go closure issue with loop variables
  • Added proper wait mechanism with group.Wait()
  • Good practice: Added comment referencing the Go FAQ about closures and goroutines
  1. Gateway Server Enhancements (gateway/server.go):
  • Added tracking of gRPC connections through conns []zrpc.Client
  • Improved shutdown sequence by stopping HTTP server before closing gRPC connections
  • Implemented parallel connection closing using threading.NewRoutineGroup
  • Good handling of connection close errors (ignoring them during shutdown)
  • Fixed potential closure issues in connection handling
  1. Test Improvements:
  • Added new test cases for multiple services shutdown scenario
  • Uses atomic operations for thread-safe testing
  • Added proper tests for both shutdown and wrap-up scenarios
  • Minor documentation improvement (MacOS capitalization fix)

Positive Aspects:

  1. Thread-safety improvements throughout the codebase
  2. Better resource cleanup during shutdown
  3. Parallel processing for performance optimization
  4. Well-documented changes with clear comments
  5. Proper test coverage for new functionality
  6. Good attention to Go-specific issues (closure handling)

Suggestions for Improvement:

  1. Consider adding log statements during shutdown sequence for better debugging
  2. Could add timeouts for the group.Wait() calls to prevent potential hangs
  3. Consider documenting the order of shutdown importance in comments

Overall Assessment:
This is a high-quality PR that improves the shutdown handling and resource management of the system. The changes are well-tested, properly documented, and follow good coding practices. Special attention has been paid to concurrent operation safety and proper resource cleanup.

The changes appear safe to merge, as they:

  • Don't break existing functionality
  • Add proper test coverage
  • Handle edge cases (like closure issues)
  • Improve system shutdown reliability

Signed-off-by: kevin <wanjunfeng@gmail.com>
@kevwan kevwan force-pushed the feat/servicegroup branch from 1c44dbe to 72cb332 Compare January 1, 2025 06:55
@kevwan kevwan added this pull request to the merge queue Jan 1, 2025
Merged via the queue into zeromicro:master with commit fcc2469 Jan 1, 2025
6 checks passed
@kevwan kevwan deleted the feat/servicegroup branch January 1, 2025 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graceful Exit Failure When Using Gateway and RPC Services Simultaneously within ServiceGroup
2 participants