commit | 57cd421de3b681b4e401dcc5d965671362663998 | [log] [tgz] |
---|---|---|
author | Jens Geyer <jensg@apache.org> | Mon Dec 08 21:25:00 2014 +0100 |
committer | Jens Geyer <jensg@apache.org> | Mon Dec 08 21:31:33 2014 +0100 |
tree | 46d860e4e1241b80b8bea822492fada43e9da224 | |
parent | 38a1c66428af48e59ff15f3ef40b04128ba52036 [diff] |
THRIFT-2881 Handle errors from Accept() correctly Client: Go Patch: awaw fumin <awawfumin@gmail.com> This closes #309 Often in tests, servers are started and closed when a test case is finished, as in the standard library's "httptest" package. http://golang.org/pkg/net/http/httptest/#example_Server However, currently the "p.quit" channel of TSimpleServer does not correctly handle the case when the listener socket is Closed, resulting in spurious logs with the text "Accept err: ...". For details of handling closed listener sockets, see https://code.google.com/p/go/issues/detail?id=4373 http://zhen.org/blog/graceful-shutdown-of-go-net-dot-listeners/ http://stackoverflow.com/a/13419724/2182406
diff --git a/lib/go/thrift/simple_server.go b/lib/go/thrift/simple_server.go index 9a27215..a54d804 100644 --- a/lib/go/thrift/simple_server.go +++ b/lib/go/thrift/simple_server.go
@@ -120,15 +120,14 @@ func (p *TSimpleServer) AcceptLoop() error { for { - select { - case <-p.quit: - return nil - default: - } - client, err := p.serverTransport.Accept() if err != nil { - log.Println("Accept err: ", err) + select { + case <-p.quit: + return nil + default: + } + return err } if client != nil { go func() {