Skip to content

Commit

Permalink
Merge pull request #6 from ssgreg/feature/initial
Browse files Browse the repository at this point in the history
fix: nil instead of http.ErrServerClosed in RunServer
  • Loading branch information
ssgreg committed Oct 8, 2018
2 parents 4e0bacb + b259e3d commit a9aa26b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (

// RunServer starts the server synchronously with the given context, server
// and listener. The server can be gracefully shut down using the given context.
//
// RunServer returns nil in case of ErrServerClosed.
func RunServer(ctx context.Context, s *http.Server, l net.Listener) (err error) {
var shutdownError error
defer func() {
Expand All @@ -21,6 +23,9 @@ func RunServer(ctx context.Context, s *http.Server, l net.Listener) (err error)
fmt.Fprintf(os.Stderr, "%s\n", err.Error())
}
}
if err == http.ErrServerClosed {
err = nil
}
}()

var wg sync.WaitGroup
Expand Down
4 changes: 2 additions & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Test_Shutdown(t *testing.T) {
}()

err = RunServer(context.Background(), &s, l)
require.Error(t, err, "http: Server closed")
require.NoError(t, err)
}

func Test_ShutdownWithContext(t *testing.T) {
Expand All @@ -37,5 +37,5 @@ func Test_ShutdownWithContext(t *testing.T) {

s := http.Server{}
err = RunServer(serverCtx, &s, l)
require.Error(t, err, "http: Server closed")
require.NoError(t, err)
}

0 comments on commit a9aa26b

Please sign in to comment.