-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
cmd/vet, os/signal: possible false-positive in sigchanyzer check when os.Signal channel is unused #45043
Comments
I am not sure I understand why this is safe yet. (So no informed cmd/vet opinion yet.) |
This came up in CL 217765 for #36976, where I copied a function from |
Code like It's not safe to write code like c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
// use c somewhere because the fact that the runtime uses a non-blocking send means that if the channel is unbuffered signals can be lost. In the case where the |
Roger that, thanks everyone for the discussion. I shall send a change tomorrow morning/afternoon, and get this fixed. |
Thanks for the pointer to |
@odeke-em , I would like to fix this in the |
All yours, thank you @AGMETEOR and welcome to the Go project, great to have you become a contributor! |
Is the pull request for this going to get in for 1.17? Thanks. |
It is! Just got stalled. @cuonglm, let’s take over, @AG-Meteor we can
select another bug later on, thanks for the contributions and offline we
can work on something else :-)
…On Mon, Apr 19, 2021 at 4:00 PM Ian Lance Taylor ***@***.***> wrote:
Is the pull request for this going to get in for 1.17? Thanks.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#45043 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABFL3V34M3M74RVMIEMF3IDTJSYZ3ANCNFSM4ZHJ6TCA>
.
|
Change https://golang.org/cl/311729 mentions this issue: |
Permit signal.Notify(make(chan os.Signal)) which is valid code, given that the channel isn't read elsewhere, the fact that signals can be lost is unimportant. Updates golang/go#45043 Change-Id: Ie984dfeedbb4e1e33a29391c3abb1fc83299fed3 Reviewed-on: https://go-review.googlesource.com/c/tools/+/311729 Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Change https://golang.org/cl/312631 mentions this issue: |
I can't understant upgrade golanglint but it still: sigchanyzer: misuse of unbuffered os.Signal channel as argument to signal.Notify |
@wnz27 This issue is closed and we believe that it is fixed. If you have a case where the warning is being issued inappropriately, please open a new issue with instructions for how to reproduce the problem. If you are asking a question, please see https://golang.org/wiki/Questions. Thanks. |
thanks, i feel sorry for that |
This looks like a false positive in go vet. See golang/go#45043 However, it should be fine to just buffer the channel to silence go vet, as was discussed in the issue. Ideally we could silence the error, but there is no way to ignore a line in a file for go vet: golang/go#17058
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I wrote a program that appears to be correct. It uses
signal.Notify
to catch SIGINT signals to prevent default handling but otherwise completely ignore them:Then ran
gotip vet .
on it.What did you expect to see?
No vet report, because as far as I can tell the os.Signal channel doesn't need to be buffered when it's completely unused.
What did you see instead?
CC @odeke-em, @ianlancetaylor, @timothy-king.
The text was updated successfully, but these errors were encountered: