From f3a519393ad1747849043e62ee58d65a6b73ea63 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 4 Sep 2017 19:12:44 -0400 Subject: nslcd_systemd: backoff on temporary net errors The logic for backof size is based on the net/http server. --- nslcd_systemd/nslcd_systemd.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'nslcd_systemd') 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 -- cgit v1.2.3-2-g168b