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

False positive on empty ctx.Done() #97

Closed
igorfraa opened this issue Nov 13, 2023 · 4 comments
Closed

False positive on empty ctx.Done() #97

igorfraa opened this issue Nov 13, 2023 · 4 comments

Comments

@igorfraa
Copy link

igorfraa commented Nov 13, 2023

Per convention, ctx.Done() is normally nil for an empty context

example valid code:

func main() {
	ctx := context.Background()
	select {
	case <-ctx.Done():
		log.Println("context done")
	}
}

nilaway output:

 error: Potential nil panic detected. Observed nil flow from source to dereference point: 
        -> context/context.go:184:9: literal `nil` returned from `Done()` in position 0
        -> context/context.go:105:2: returned as result 0 from interface method `Context.Done()` (implemented by `emptyCtx.Done()`)
        -> example.go:11:9: result 0 of `Done()` uninitialized; nil channel accessed
@sonalmahajan15
Copy link
Contributor

@igorfraa - acknowledged. Thanks for reporting this issue. NilAway currently does not have support modeled for the context package. We will work on adding this support in NilAway. Also, feel free to raise a PR if you already have a working solution for this problem. :)

@FiloSottile
Copy link

This is not about context in particular. In general, receiving on a nil channel does not lead to a panic. It will block forever which might not be the desired outcome, but for example as part of a select it's potentially perfectly intended.

@orsinium
Copy link

Filippo is right, read from a nil channel doesn't panic by design and so should not be reported by NilAway. And the empty context is the best example of when it is an intended behavior.

@igorfraa
Copy link
Author

looks like a specific case of a more general "nil channel inside select" #98

I will close this one in favour of !98 and will try to look into that

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

No branches or pull requests

4 participants