Skip to content

Conversation

@fivecut
Copy link

@fivecut fivecut commented Apr 16, 2025

fix the misuse of unbuffered os.Signal channel as argument to signal.Notify

…gnal.Notify

Signed-off-by: fivecut <fivecut@126.com>
Copy link

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 PR fixes a concurrency issue related to signal handling in the proxy server's shutdown mechanism. The change addresses the misuse of an unbuffered channel with signal.Notify, which can cause signal delivery problems.

  • Converts an unbuffered os.Signal channel to a buffered channel with capacity 1


func waitForServerShutdown(httpServer *http.Server, closableComponents *data.ClosableComponentsHandler) {
quit := make(chan os.Signal)
quit := make(chan os.Signal, 1)
Copy link

Copilot AI Jul 23, 2025

Choose a reason for hiding this comment

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

Good fix! Using a buffered channel with capacity 1 prevents potential signal loss. The Go documentation recommends buffered channels for signal.Notify to ensure signals are not dropped if the receiver is not immediately ready.

Suggested change
quit := make(chan os.Signal, 1)
quit := make(chan os.Signal, 1) // Buffered channel with capacity 1 to prevent signal loss

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

1 participant