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 <javascript:>> 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 <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.

Reply via email to