-
-
Notifications
You must be signed in to change notification settings - Fork 125
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
SIGHUP channel should be buffered #1
Comments
I assume it's because an unbuffered channel would block the sender and you don't want the runtime to block. |
The runtime will drop the signal on the floor if the channel is not ready, that's why the docs recommend a buffered channel. In this case the channel won't be ready if (1) the loop hasn't started yet or (2) a Close is already in progress. (2) is arguably good, we don't want to drop the connection twice in that case. I thought (1) was fine too, but then I realized there is no guarantee of when the goroutine will start, so technically this is not airtight. On the other hand, if the goroutine never starts, the point is moot because the signals will not get processed. The buffer only helps with a signal that arrives before the loop starts, which in practice should be a narrow window. On balance, I think it's fine to use the unbuffered channel. |
(But thank you for looking at the code and reporting this! Glad to know there are eyes on it!) |
ciao Filippo,
according to the
signals.Notify
documentation, the channel should be buffered:I have to admit that I have always been partially confused by this requirement and by the various discussions that pop up from googling the subject.
Maybe in this particular case there is no practical difference but I noticed it:
yubikey-agent/main.go
Line 42 in 0096c09
The text was updated successfully, but these errors were encountered: