Skip to content

Commit

Permalink
Fixed http listener error. (zeromicro#843)
Browse files Browse the repository at this point in the history
  • Loading branch information
weicut authored Jul 24, 2021
1 parent 089cdaa commit b812e74
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions rest/internal/starter.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ func StartHttps(host string, port int, certFile, keyFile string, handler http.Ha
})
}

func start(host string, port int, handler http.Handler, run func(srv *http.Server) error) error {
func start(host string, port int, handler http.Handler, run func(srv *http.Server) error) (err error) {
server := &http.Server{
Addr: fmt.Sprintf("%s:%d", host, port),
Handler: handler,
}
waitForCalled := proc.AddWrapUpListener(func() {
server.Shutdown(context.Background())
})
defer waitForCalled()
defer func() {
if err == http.ErrServerClosed {
waitForCalled()
}
}()

return run(server)
}

0 comments on commit b812e74

Please sign in to comment.