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

doc: Writing web applications ignores error from ListenAndServe #19511

Closed
joneskoo opened this Issue Mar 11, 2017 · 4 comments

Comments

Projects
None yet
6 participants
@joneskoo
Contributor

joneskoo commented Mar 11, 2017

@campoy:
Does everyone forget to check the error on ListenAndServe? #golang
https://twitter.com/francesc/status/838547440710012928

Nothing in this tutorial https://golang.org/doc/articles/wiki/ Writing Web Applications, in the Articles section of documentation, seems to indicate that ListenAndServe may return an error. Errors should be checked.

https://golang.org/pkg/net/http/#ListenAndServe
func ListenAndServe(addr string, handler Handler) error
ListenAndServe always returns a non-nil error.

Since I don't see an issue opened by @campoy , I'm opening one.

EDIT: Clarified that the issue is in Article, not the package documentation.

@qqiao

This comment has been minimized.

qqiao commented Mar 12, 2017

The error isn't ignored in the example. It was first logged, then caused an os.Exit(1)

https://golang.org/src/log/log.go?s=9066:9094#L291

@bradfitz bradfitz added this to the Go1.9Maybe milestone Mar 21, 2017

@ianlancetaylor ianlancetaylor modified the milestones: Go1.10, Go1.9Maybe Aug 3, 2017

@ianlancetaylor

This comment has been minimized.

Contributor

ianlancetaylor commented Aug 3, 2017

Ping @campoy

@campoy

This comment has been minimized.

Contributor

campoy commented Aug 3, 2017

The documentation pointed by @joneskoo is indeed failing silently if http.ListenAndServe returns an error.
Since we're not using the Shutdown method, I'd say that it's safe to simply add log.Fatal.
I'll send a CL

@gopherbot

This comment has been minimized.

gopherbot commented Aug 3, 2017

Change https://golang.org/cl/53071 mentions this issue: docs: add error handling on http.ListenAndServe

@gopherbot gopherbot closed this in e3e09e3 Aug 31, 2017

@golang golang locked and limited conversation to collaborators Aug 31, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.