Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions daemon/algod/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@
return errors.New(
"Initialize() overflowed when adding up ReservedFDs and RestConnectionsHardLimit; decrease them")
}
err = util.SetFdSoftLimit(fdRequired)
if cfg.EnableP2P {

Check warning on line 132 in daemon/algod/server.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/server.go#L132

Added line #L132 was not covered by tests
// TODO: Decide if this is too much, or not enough.
fdRequired = ot.Add(fdRequired, 512)

Check warning on line 134 in daemon/algod/server.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/server.go#L134

Added line #L134 was not covered by tests
}
err = util.RaiseFdSoftLimit(fdRequired)

Check warning on line 136 in daemon/algod/server.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/server.go#L136

Added line #L136 was not covered by tests
if err != nil {
return fmt.Errorf("Initialize() err: %w", err)
}
Expand All @@ -141,7 +145,7 @@
return errors.New(
"Initialize() overflowed when adding up fdRequired and 1000 needed for pebbledb")
}
err = util.SetFdSoftLimit(fdRequired)
err = util.RaiseFdSoftLimit(fdRequired)

Check warning on line 148 in daemon/algod/server.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/server.go#L148

Added line #L148 was not covered by tests
if err != nil {
return fmt.Errorf("Initialize() failed to set FD limit for pebbledb backend, err: %w", err)
}
Expand Down Expand Up @@ -190,7 +194,7 @@
}
}
}
fdErr = util.SetFdSoftLimit(maxFDs)
fdErr = util.RaiseFdSoftLimit(maxFDs)

Check warning on line 197 in daemon/algod/server.go

View check run for this annotation

Codecov / codecov/patch

daemon/algod/server.go#L197

Added line #L197 was not covered by tests
if fdErr != nil {
// do not fail but log the error
s.log.Errorf("Failed to set a new RLIMIT_NOFILE value to %d (max %d): %s", fdRequired, hard, fdErr.Error())
Expand Down
18 changes: 18 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
return rLimit.Cur, rLimit.Max, nil
}

// RaiseFdSoftLimit raises the file descriptors soft limit to the specified value,
// or leave it unchanged if the value is less than the current.
func RaiseFdSoftLimit(newLimit uint64) error {
soft, hard, err := GetFdLimits()
if err != nil {
return fmt.Errorf("RaiseFdSoftLimit() err: %w", err)

Check warning on line 44 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L41-L44

Added lines #L41 - L44 were not covered by tests
}
if newLimit <= soft {

Check warning on line 46 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L46

Added line #L46 was not covered by tests
// Current limit is sufficient; no need to change it.
return nil

Check warning on line 48 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L48

Added line #L48 was not covered by tests
}
if newLimit > hard {

Check warning on line 50 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L50

Added line #L50 was not covered by tests
// New limit exceeds the hard limit; set it to the hard limit.
newLimit = hard

Check warning on line 52 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L52

Added line #L52 was not covered by tests
}
return SetFdSoftLimit(newLimit)

Check warning on line 54 in util/util.go

View check run for this annotation

Codecov / codecov/patch

util/util.go#L54

Added line #L54 was not covered by tests
}

// SetFdSoftLimit sets a new file descriptors soft limit.
func SetFdSoftLimit(newLimit uint64) error {
var rLimit syscall.Rlimit
Expand Down
5 changes: 5 additions & 0 deletions util/util_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func GetFdLimits() (soft uint64, hard uint64, err error) {
return math.MaxUint64, math.MaxUint64, nil // syscall.RLIM_INFINITY
}

// RaiseFdSoftLimit raises the file descriptors soft limit.
func RaiseFdSoftLimit(_ uint64) error {
return nil
}

// SetFdSoftLimit sets a new file descriptors soft limit.
func SetFdSoftLimit(_ uint64) error {
return nil
Expand Down
Loading