Skip to content

doc: Writing web applications ignores error from ListenAndServe #19511

Closed

Description

@joneskoo

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

Activity

  1. qqiao commented on Mar 12, 2017

    @qqiao

    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

  2. added this to the Go1.9Maybe milestone on Mar 21, 2017
  3. ianlancetaylor commented on Aug 3, 2017

    @ianlancetaylor
    Contributor

    Ping @campoy

  4. campoy commented on Aug 3, 2017

    @campoy
    Contributor

    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

  5. gopherbot commented on Aug 3, 2017

    @gopherbot
    Contributor

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

  6. locked and limited conversation to collaborators on Aug 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions