From 643cd143070d779d4697ef7eeecd3dbf5f5e24ff Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 18 Dec 2017 13:20:43 -0500 Subject: nslcd_server: respect all values if limits.Timeout < limits.ReadTimeout + limits.WriteTimeout If Timeout : 3s ReadTimeout : 2s WriteTimeout : 2s Then before the effective total Timeout was 2s+2s=4s. That is wrong. It should only be that the Write phase gets to use the full 2s if the Read phase uses <= 1s. --- nslcd_server/func_handlerequest.go.gen | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/nslcd_server/func_handlerequest.go.gen b/nslcd_server/func_handlerequest.go.gen index 7c28e7c..00e9663 100755 --- a/nslcd_server/func_handlerequest.go.gen +++ b/nslcd_server/func_handlerequest.go.gen @@ -84,14 +84,20 @@ func HandleRequest(backend Backend, limits Limits, conn Conn, cred unix.Ucred) ( }() now := time.Now() + deadlineAll := time.Time{} + deadlineRead := time.Time{} if limits.Timeout != 0 { - err = conn.SetDeadline(now.Add(limits.Timeout)) - if err != nil { - return err - } + deadlineAll = now.Add(limits.Timeout) } if limits.ReadTimeout != 0 { - err = conn.SetReadDeadline(now.Add(limits.ReadTimeout)) + deadlineRead = now.Add(limits.ReadTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineRead) { + deadlineRead = deadlineAll + } + } + deadlineWrite := deadlineAll + if !deadlineRead.IsZero() { + err = conn.SetReadDeadline(deadlineRead) if err != nil { return err } @@ -144,7 +150,13 @@ while read -r request; do esac ) if limits.WriteTimeout != 0 { - err = out.SetWriteDeadline(time.Now().Add(limits.WriteTimeout)) + deadlineWrite = time.Now().Add(limits.WriteTimeout) + if !deadlineAll.IsZero() && deadlineAll.Before(deadlineWrite) { + deadlineWrite = deadlineAll + } + } + if !deadlineWrite.IsZero() { + err = out.SetWriteDeadline(deadlineWrite) if err != nil { return err } -- cgit v1.2.3-2-g168b