summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2017-09-04 19:12:44 -0400
committerLuke Shumaker <lukeshu@lukeshu.com>2017-09-08 16:55:55 -0400
commitf3a519393ad1747849043e62ee58d65a6b73ea63 (patch)
tree527cf0530293ea56081e55729925aaeedebf4027
parent3c4b49aed2451c4ae4c3e1273d920016ed646df6 (diff)
nslcd_systemd: backoff on temporary net errors
The logic for backof size is based on the net/http server.
-rw-r--r--nslcd_systemd/nslcd_systemd.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/nslcd_systemd/nslcd_systemd.go b/nslcd_systemd/nslcd_systemd.go
index 2839af4..0856b70 100644
--- a/nslcd_systemd/nslcd_systemd.go
+++ b/nslcd_systemd/nslcd_systemd.go
@@ -38,6 +38,7 @@ import (
"os"
"os/signal"
"sync"
+ "time"
"git.lukeshu.com/go/libnslcd/nslcd_server"
"git.lukeshu.com/go/libsystemd/sd_daemon"
@@ -136,6 +137,7 @@ func Main(backend Backend) uint8 {
defer sd_daemon.Recover()
defer wg.Done()
+ var tempDelay time.Duration
last := false
for !last {
conn, err := socket.Accept()
@@ -144,6 +146,15 @@ func Main(backend Backend) uint8 {
last = true
} else if ne, ok := err.(net.Error); ok && ne.Temporary() {
sd_daemon.Log.Notice(fmt.Sprintf("%v", err))
+ if tempDelay == 0 {
+ tempDelay = 5 * time.Millisecond
+ } else {
+ tempDelay *= 2
+ }
+ if max := 1 * time.Second; tempDelay > max {
+ tempDelay = max
+ }
+ time.Sleep(tempDelay)
} else {
socket_error <- err
last = true