You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Try the program below. If you run it and press Ctrl-C it exits. If you run it, then hit localhost:8080/foo with firefox or chrome, then Ctrl-C the program, it will hang. This happens because the http.Server created inside func (s *GracefulServer) Serve(...) doesn't have a read timeout set.
There's an easy fix, I'll send a pull request.
package main
import (
"fmt""github.com/braintree/manners""io""net/http""os""os/signal""syscall"
)
varquitChan=make(chan os.Signal, 1)
varserver=manners.NewServer()
funcHello(w http.ResponseWriter, req*http.Request) {
io.WriteString(w, "hello, world!\n")
}
/* it looks like manners only shuts down if the client doesn't use persistent connection; e.g. if you run this, then make a request with curl, then ctrl-c this process, it shuts down gracefully. But if you make the request with Chrome or Firefox, then ctrl-c this process, the http server doesn't quit until you close the browser tab (firefox) or entire browser (chrome) */funcwaitForSignal() {
fmt.Println("waiting for signal")
<-quitChanfmt.Println("got signal")
server.Shutdown<-true
}
funcmain() {
signal.Notify(quitChan, syscall.SIGINT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM)
http.HandleFunc("/foo", Hello)
gowaitForSignal()
fmt.Println("listening...")
server.ListenAndServe(":8080", nil)
fmt.Println("exiting")
}
The text was updated successfully, but these errors were encountered:
Can confirm this behavior. Was trying to setup a reload after receiving a syscall.SIGINT. LisenAndServe stops serving new requests but hangs, preventing reload.
Try the program below. If you run it and press Ctrl-C it exits. If you run it, then hit localhost:8080/foo with firefox or chrome, then Ctrl-C the program, it will hang. This happens because the http.Server created inside func (s *GracefulServer) Serve(...) doesn't have a read timeout set.
There's an easy fix, I'll send a pull request.
The text was updated successfully, but these errors were encountered: