1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:54:44 -07:00

cmd/tipgodoc: Kill godoc process if http.ListenAndServe fails

Currently, if for some reason http.ListenAndServe fails, any running
running godoc processes don't get killed. I don't think this would ever
actually happen because, with godoc being set up in a separate go
routine, http.ListenAndServe would always(?) fail before the godoc
server started.

This change ensures that, if a Proxy has a cmd, it is closed when
http.ListenAndServe fails.

Change-Id: I0d3bfae0c16bc583248c2052a4d7a84c95127e76
Reviewed-on: https://go-review.googlesource.com/8570
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Tommy Schaefer 2015-04-07 15:03:20 -05:00 committed by Brad Fitzpatrick
parent 8a634c5831
commit 0770aced4f

View File

@ -36,7 +36,11 @@ func main() {
p := new(Proxy)
go p.run()
http.Handle("/", p)
log.Fatal(http.ListenAndServe(":8080", nil))
if err := http.ListenAndServe(":8080", nil); err != nil {
p.stop()
log.Fatal(err)
}
}
// Proxy implements the tip.golang.org server: a reverse-proxy
@ -85,6 +89,14 @@ func (p *Proxy) run() {
}
}
func (p *Proxy) stop() {
p.mu.Lock()
defer p.mu.Unlock()
if p.cmd != nil {
p.cmd.Process.Kill()
}
}
// poll runs from the run loop goroutine.
func (p *Proxy) poll() {
heads := gerritMetaMap()