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

caddyauth: fix unbuffered channel passed to signal.Notify #3895

Merged
merged 1 commit into from
Dec 1, 2020
Merged

caddyauth: fix unbuffered channel passed to signal.Notify #3895

merged 1 commit into from
Dec 1, 2020

Conversation

cuonglm
Copy link
Contributor

@cuonglm cuonglm commented Dec 1, 2020

The docs at os/signal.Notify warn about this signal delivery loss bug at
https://golang.org/pkg/os/signal/#Notify, which says:

Package signal will not block sending to c: the caller must ensure
that c has sufficient buffer space to keep up with the expected signal
rate. For a channel used for notification of just one signal value,
a buffer of size 1 is sufficient.

Caught by a static analysis tool from Orijtech, Inc. called "sigchanyzer"

@CLAassistant
Copy link

CLAassistant commented Dec 1, 2020

CLA assistant check
All committers have signed the CLA.

…Notify

The docs at os/signal.Notify warn about this signal delivery loss bug at
https://golang.org/pkg/os/signal/#Notify, which says:

    Package signal will not block sending to c: the caller must ensure
    that c has sufficient buffer space to keep up with the expected signal
    rate. For a channel used for notification of just one signal value,
    a buffer of size 1 is sufficient.

Caught by a static analysis tool from Orijtech, Inc. called "sigchanyzer"
@cuonglm
Copy link
Contributor Author

cuonglm commented Dec 1, 2020

Related Go issue: golang/go#9399

@francislavoie
Copy link
Member

francislavoie commented Dec 1, 2020

What issue does this actually solve here? This is just a one-off command used for hashing passwords, and it's just meant to capture ^C to not break terminal state. I've not seen issues with that usecase. 🤔

That said, this looks fine, just trying to understand.

@cuonglm
Copy link
Contributor Author

cuonglm commented Dec 1, 2020

What issue does this actually solve here? This is just a one-off command used for hashing passwords, and it's just meant to capture ^C to not break terminal state. I've not seen issues with that usecase.

That said, this looks fine, just trying to understand.

I invite you to read golang/go#9399

Without using buffered channel, there can be a risk that the signal is lost, because it's sent before the channel is ready. Sure it's hard to get in to trouble with this use case, but I think it's better to always use the right (and safe) way that the language offers.

@francislavoie francislavoie added this to the v2.3.0 milestone Dec 1, 2020
@francislavoie francislavoie added the under review 🧐 Review is pending before merging label Dec 1, 2020
@francislavoie francislavoie changed the title modules/caddyhttp/caddyauth: fix unbuffered channel passed to signal.Notify caddyauth: fix unbuffered channel passed to signal.Notify Dec 1, 2020
Copy link
Member

@mholt mholt left a comment

Choose a reason for hiding this comment

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

I agree this is probably an insignificant change, but, we do use a buffer size of 1 in sigtrap.go already, so I guess we can be consistent here. Thanks for the PR!

@mholt mholt merged commit 4cff36d into caddyserver:master Dec 1, 2020
@mholt mholt removed the under review 🧐 Review is pending before merging label Jan 6, 2022
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.

None yet

4 participants