Ah - that explains it. Even though the bug's been fixed, the behaviour's been bugging me! Thanks for the explanation :-)
On Saturday, July 15, 2017 at 11:33:37 AM UTC+10, Matt Harden wrote: > > The reason it was exiting was because you didn't wait at the end of main() > after http.ListenAndServe exited. ListenAndServe will exit as soon as the > listening socket is closed, but there can still be connected sockets open > at that time (including the one handling /stop). When main returns, the Go > program exits, and all other goroutines cease to exist. > > On Thu, Jul 13, 2017 at 11:56 PM <char...@gmail.com <javascript:>> wrote: > >> Well that makes sense! But shouldn't it have hung instead of exiting then? >> >> On Friday, July 14, 2017 at 12:01:36 PM UTC+10, Matt Harden wrote: >> >>> Oh! In retrospect, it's obvious. The whole point of Shutdown() is to >>> give running handlers a chance to finish, so if we call it from within a >>> handler (and wait for it to finish there) then we have a deadlock. >>> >>> On Sun, Jul 9, 2017 at 10:10 PM <char...@gmail.com> wrote: >>> >> Yes! That works :-) Thanks so much. >>>> >>>> So apparently we cannot call *net.http.Server.Shutdown()* from a >>>> handler function. Maybe this should be added to the docs. >>>> >>>> >>>> On Monday, July 10, 2017 at 3:05:10 PM UTC+10, mikioh...@gmail.com >>>> wrote: >>>>> >>>>> calling Shutdown method of http.Server in a registered HTTP handler >>>>> probably may prevent the package internal helpers from marking the >>>>> inflight >>>>> connection idle. so you can write like the following: >>>>> >>>>> http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) { >>>>> >>>>> fmt.Fprintf(w, "shutdown request accepted") >>>>> >>>>> go func() { >>>>> >>>>> log.Println("shutting down the server: >>>>> "srv.Shutdown(context.Background()) >>>>> >>>>> close(done) >>>>> >>>>> }() >>>>> >>>>> }) >>>>> >>>>> see https://golang.org/pkg/net/http/#Server.Shutdown for further >>>>> information. >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "golang-nuts" group. >>>> >>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to golang-nuts...@googlegroups.com. >>> >>> >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.