Print accept errors, sleep on tmp ones

This commit is contained in:
Derek Collison
2013-06-13 08:33:20 -07:00
parent d07e34e001
commit a9d5bd7334
2 changed files with 15 additions and 0 deletions

View File

@@ -40,4 +40,8 @@ const (
DEFAULT_FLUSH_DEADLINE = 500 * time.Millisecond
DEFAULT_HTTP_PORT = 8333
// Accept sleep times on temporary errors
ACCEPT_MIN_SLEEP = 10 * time.Millisecond
ACCEPT_MAX_SLEEP = 1 * time.Second
)

View File

@@ -173,14 +173,25 @@ func (s *Server) AcceptLoop() {
s.running = true
s.mu.Unlock()
tmpDelay := ACCEPT_MIN_SLEEP
for s.isRunning() {
conn, err := l.Accept()
if err != nil {
if ne, ok := err.(net.Error); ok && ne.Temporary() {
Debug("Temporary Accept Error(%v), sleeping %dms",
ne, tmpDelay/time.Millisecond)
time.Sleep(tmpDelay)
tmpDelay *= 2
if tmpDelay > ACCEPT_MAX_SLEEP {
tmpDelay = ACCEPT_MAX_SLEEP
}
} else {
Logf("Accept error: %v", err)
}
continue
}
tmpDelay = ACCEPT_MIN_SLEEP
s.createClient(conn)
}
s.done <- true