Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-14 Thread Matt Harden
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

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-14 Thread charlievx
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

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-14 Thread amkguo
The same issue as this: https://groups.google.com/forum/#!searchin/golang-nuts/shutdown%7Csort:relevance/golang-nuts/Aca1YAX6Uxc/o6kDLqxIAQAJ I've file a bug report here: https://github.com/golang/go/issues/19579 Andrew -- You received this message because you are subscribed to the Google

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-13 Thread Matt Harden
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 wrote: > Yes! That works :-)

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
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

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread mikioh . mikioh
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,

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Interesting - now I get the same messages: 2017/07/10 13:23:17 Server starting up... 2017/07/10 13:23:22 Server shutting down... test - before shutdown But the program doesn't stop! I need to Ctrl+C to stop it... I don't get it - why doesn't server.Shutdown() just work? On Monday, July 10,

Re: [go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread Matt Harden
Try a channel to wait for shutdown in main. func main() { srv := {Addr: ":8080", Handler: http.DefaultServeMux} *done := make(chan struct{})* http.Handle("/web/", http.FileServer(http.Dir("./"))) http.HandleFunc("/stop", func(w http.ResponseWriter, r *http.Request) {

[go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread charlievx
Just tried it but it doesn't work. The problem I started from is that server.Shutdown didn't wait for my requests to complete. (To check this I put in the time.Sleep(6000 * time.Millisecond)). When I narrowed down the problem it showed me that code after the Shutdown call wasn't being

[go-nuts] Re: http.Server.Shutdown() crashing?

2017-07-09 Thread Elias Naur
Your main goroutine probably exits before the handler gets to write "after shutdown" to the console. Try adding a time.Sleep(1*time.Second) as the very last line in main(). - elias On Sunday, July 9, 2017 at 1:53:36 PM UTC+2, char...@gmail.com wrote: > > Hi, > > Go code after calling