Skip to content
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

doesn't shutdown when used with clients using persistent connections #19

Closed
kmanley opened this issue Aug 8, 2014 · 2 comments
Closed

Comments

@kmanley
Copy link
Contributor

kmanley commented Aug 8, 2014

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"
)

var quitChan = make(chan os.Signal, 1)
var server = manners.NewServer()

func Hello(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) */
func waitForSignal() {
    fmt.Println("waiting for signal")
    <-quitChan
    fmt.Println("got signal")
    server.Shutdown <- true
}

func main() {

    signal.Notify(quitChan, syscall.SIGINT, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM)
    http.HandleFunc("/foo", Hello)
    go waitForSignal()
    fmt.Println("listening...")
    server.ListenAndServe(":8080", nil)
    fmt.Println("exiting")
}
@bryfry
Copy link

bryfry commented Aug 9, 2014

Can confirm this behavior. Was trying to setup a reload after receiving a syscall.SIGINT. LisenAndServe stops serving new requests but hangs, preventing reload.

@lionelbarrow
Copy link
Contributor

This is fixed with the merge of the non-backwards-compat branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants