File tree Expand file tree Collapse file tree 5 files changed +22
-13
lines changed Expand file tree Collapse file tree 5 files changed +22
-13
lines changed Original file line number Diff line number Diff line change @@ -950,10 +950,11 @@ func makeDatabaseHandles() int {
950
950
if err != nil {
951
951
Fatalf ("Failed to retrieve file descriptor allowance: %v" , err )
952
952
}
953
- if err := fdlimit .Raise (uint64 (limit )); err != nil {
953
+ raised , err := fdlimit .Raise (uint64 (limit ))
954
+ if err != nil {
954
955
Fatalf ("Failed to raise file descriptor allowance: %v" , err )
955
956
}
956
- return limit / 2 // Leave half for networking and other stuff
957
+ return int ( raised / 2 ) // Leave half for networking and other stuff
957
958
}
958
959
959
960
// MakeAddress converts an account specified directly as a hex encoded string or
Original file line number Diff line number Diff line change @@ -26,21 +26,24 @@ import "syscall"
26
26
27
27
// Raise tries to maximize the file descriptor allowance of this process
28
28
// to the maximum hard-limit allowed by the OS.
29
- func Raise (max uint64 ) error {
29
+ func Raise (max uint64 ) ( uint64 , error ) {
30
30
// Get the current limit
31
31
var limit syscall.Rlimit
32
32
if err := syscall .Getrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
33
- return err
33
+ return 0 , err
34
34
}
35
35
// Try to update the limit to the max allowance
36
36
limit .Cur = limit .Max
37
37
if limit .Cur > int64 (max ) {
38
38
limit .Cur = int64 (max )
39
39
}
40
40
if err := syscall .Setrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
41
- return err
41
+ return 0 , err
42
+ }
43
+ if err := syscall .Getrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
44
+ return 0 , err
42
45
}
43
- return nil
46
+ return limit . Cur , nil
44
47
}
45
48
46
49
// Current retrieves the number of file descriptors allowed to be opened by this
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ func TestFileDescriptorLimits(t *testing.T) {
36
36
if limit , err := Current (); err != nil || limit <= 0 {
37
37
t .Fatalf ("failed to retrieve file descriptor limit (%d): %v" , limit , err )
38
38
}
39
- if err := Raise (uint64 (target )); err != nil {
39
+ if _ , err := Raise (uint64 (target )); err != nil {
40
40
t .Fatalf ("failed to raise file allowance" )
41
41
}
42
42
if limit , err := Current (); err != nil || limit < target {
Original file line number Diff line number Diff line change @@ -22,21 +22,26 @@ import "syscall"
22
22
23
23
// Raise tries to maximize the file descriptor allowance of this process
24
24
// to the maximum hard-limit allowed by the OS.
25
- func Raise (max uint64 ) error {
25
+ // Returns the size it was set to (may differ from the desired 'max')
26
+ func Raise (max uint64 ) (uint64 , error ) {
26
27
// Get the current limit
27
28
var limit syscall.Rlimit
28
29
if err := syscall .Getrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
29
- return err
30
+ return 0 , err
30
31
}
31
32
// Try to update the limit to the max allowance
32
33
limit .Cur = limit .Max
33
34
if limit .Cur > max {
34
35
limit .Cur = max
35
36
}
36
37
if err := syscall .Setrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
37
- return err
38
+ return 0 , err
39
+ }
40
+ // MacOS can silently apply further caps, so retrieve the actually set limit
41
+ if err := syscall .Getrlimit (syscall .RLIMIT_NOFILE , & limit ); err != nil {
42
+ return 0 , err
38
43
}
39
- return nil
44
+ return limit . Cur , nil
40
45
}
41
46
42
47
// Current retrieves the number of file descriptors allowed to be opened by this
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import "errors"
20
20
21
21
// Raise tries to maximize the file descriptor allowance of this process
22
22
// to the maximum hard-limit allowed by the OS.
23
- func Raise (max uint64 ) error {
23
+ func Raise (max uint64 ) ( uint64 , error ) {
24
24
// This method is NOP by design:
25
25
// * Linux/Darwin counterparts need to manually increase per process limits
26
26
// * On Windows Go uses the CreateFile API, which is limited to 16K files, non
@@ -30,7 +30,7 @@ func Raise(max uint64) error {
30
30
if max > 16384 {
31
31
return errors .New ("file descriptor limit (16384) reached" )
32
32
}
33
- return nil
33
+ return max , nil
34
34
}
35
35
36
36
// Current retrieves the number of file descriptors allowed to be opened by this
You can’t perform that action at this time.
0 commit comments