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

joneskoo opened this Issue Mar 11, 2017 · 4 comments


None yet
6 participants

joneskoo commented Mar 11, 2017

Does everyone forget to check the error on ListenAndServe? #golang

Nothing in this tutorial Writing Web Applications, in the Articles section of documentation, seems to indicate that ListenAndServe may return an error. Errors should be checked.
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.


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)

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

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


This comment has been minimized.


ianlancetaylor commented Aug 3, 2017

Ping @campoy


This comment has been minimized.


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


This comment has been minimized.

gopherbot commented Aug 3, 2017

Change 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.