mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Print accept errors, sleep on tmp ones
This commit is contained in:
@@ -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
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user