Skip to content

Commit

Permalink
Fix error if one of Max or Cur limit is upper than new value
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas JUHEL committed Jun 17, 2020
1 parent d6138a7 commit ca494d2
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions njs-ioutils/fileDescriptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,24 @@ func SystemFileDescriptor(newValue int) (current int, max int, err error) {
return int(rLimit.Cur), int(rLimit.Max), nil
}

rLimit.Max = uint64(newValue)
rLimit.Cur = uint64(newValue)
var chg = false

if err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
return
if newValue > int(rLimit.Max) {
chg = true
rLimit.Max = uint64(newValue)
}
if newValue > int(rLimit.Cur) {
chg = true
rLimit.Cur = uint64(newValue)
}

if chg {
if err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
return
}

return SystemFileDescriptor(0)
}

return SystemFileDescriptor(0)
return int(rLimit.Cur), int(rLimit.Max), nil
}

0 comments on commit ca494d2

Please sign in to comment.