diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2017-12-18 13:20:43 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2017-12-18 13:21:38 -0500 |
commit | 643cd143070d779d4697ef7eeecd3dbf5f5e24ff (patch) | |
tree | 6da2239154ec7dba569e9039479a44b015c44631 /nslcd_server | |
parent | 549843228517e1d72840e18caf369d211623dddb (diff) |
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.
Diffstat (limited to 'nslcd_server')
-rwxr-xr-x | nslcd_server/func_handlerequest.go.gen | 24 |
1 files 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 } |