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

doc: Writing web applications ignores error from ListenAndServe #19511

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

doc: Writing web applications ignores error from ListenAndServe #19511

joneskoo opened this issue Mar 11, 2017 · 4 comments

Comments

@joneskoo
Copy link
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
Copy link

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
Copy link
Contributor

Ping @campoy

@campoy
Copy link
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
Copy link

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

@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.
Projects
None yet
Development

No branches or pull requests

6 participants