If Accept() fails due to a closing listener, return

Other types of Accept() failures should result in a retry.
pull/2333/head
Philip O'Toole 2015-04-17 20:10:57 -07:00
parent 4a1df4c45a
commit 0b1fc43f88
2 changed files with 10 additions and 2 deletions

View File

@ -52,9 +52,13 @@ func (t *TCPServer) ListenAndServe(iface string) error {
defer t.wg.Done()
for {
conn, err := ln.Accept()
if opErr, ok := err.(*net.OpError); ok && !opErr.Temporary() {
t.Logger.Println("graphite TCP listener closed")
return
}
if err != nil {
t.Logger.Println("error accepting TCP connection", err.Error())
return
continue
}
t.wg.Add(1)

View File

@ -73,9 +73,13 @@ func (s *Server) ListenAndServe(listenAddress string) {
defer s.wg.Done()
for {
conn, err := s.listener.Accept()
if opErr, ok := err.(*net.OpError); ok && !opErr.Temporary() {
log.Println("openTSDB TCP listener closed")
return
}
if err != nil {
log.Println("error accepting openTSDB: ", err.Error())
return
continue
}
s.wg.Add(1)
go s.HandleConnection(conn)