-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
e.StartServer() vs. e.Close() etc. #1800
Comments
Wouldn't be easier to simply set |
There are other problems. 1 server can actually serve multiple listeners etc. echo instance contains 2 servers. So if you call as I would say their value is making developer life simpler for simple use cases but for more complex having server/listener embedded in echo instance it makes life harder. As soon you want to use your own server and/or listener(s) current Echo server related API methods are probably not for you - these were made for simpler cases long time ago and have evolved by adhoc patches over time. but these are not backwards compatible changes and are not going to happen soon You can do everything with just server instance. no need to call echo server related methods e := New()
e.GET("/", func(c Context) error {
return c.String(http.StatusOK, "OK")
})
// From here on work only with http.Server instance
server := http.Server{
Addr: ":8080",
Handler: e,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
e.Logger.Fatal("shutting down the server")
}
}()
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
<-quit
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
if err := server.Shutdown(ctx); err != nil {
e.Logger.Fatal(err)
} |
I agree.
Again, I agree and see the value for a painless start. |
I think we can close this issue. |
Issue Description
If
e.StartServer()
was used to start a custom http server,e.Close()
ande.Shutdown()
will not work as expected.The problem seems to be that
e.Close()
ande.Shutdown()
friends act one.Server
which is not updated bye.StartServer()
. This was raised back in #1266 and is somewhat related to #1793.Checklist
Expected behaviour
e.Close()
ande.Shutdown()
should tear down servers started viae.StartServer()
.Actual behaviour
e.Close()
ande.Shutdown()
tear down the default server.Steps to reproduce
Working code to debug
execute with:
go test -run TestEchoShutdown2
Version/commit
6f9b71c
The text was updated successfully, but these errors were encountered: