1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-22 00:25:58 +01:00

Increase file descriptor limit at startup.

This commit is contained in:
Juliusz Chroboczek 2021-07-29 14:26:41 +02:00
parent 82b10b2c10
commit a78fb6d747
5 changed files with 62 additions and 1 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/jech/galene/diskwriter"
"github.com/jech/galene/group"
"github.com/jech/galene/ice"
"github.com/jech/galene/limit"
"github.com/jech/galene/turnserver"
"github.com/jech/galene/webserver"
)
@ -104,6 +105,13 @@ func main() {
}()
}
n, err := limit.Nofile(0xFFFF)
if err != nil {
log.Printf("Couldn't set file descriptor limit: %v", err)
} else if n < 0xFFFF {
log.Printf("File descriptor limit is %v, please increase it!", n)
}
ice.ICEFilename = filepath.Join(dataDir, "ice-servers.json")
go group.ReadPublicGroups()

1
go.mod
View file

@ -13,4 +13,5 @@ require (
github.com/pion/turn/v2 v2.0.5
github.com/pion/webrtc/v3 v3.0.31
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c
)

3
go.sum
View file

@ -122,8 +122,9 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c h1:F1jZWGFhYfh0Ci55sIpILtKKK8p3i2/krTr0H1rg74I=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

7
limit/limit.go Normal file
View file

@ -0,0 +1,7 @@
// +build windows plan9
package limit
func Nofile(desired uint64) (uint64, error) {
return desired, nil
}

44
limit/limit_unix.go Normal file
View file

@ -0,0 +1,44 @@
// +build !windows
// +build !plan9
package limit
import (
"golang.org/x/sys/unix"
)
func Nofile(desired uint64) (uint64, error) {
var old unix.Rlimit
err := unix.Getrlimit(unix.RLIMIT_NOFILE, &old)
if err != nil {
return 0, err
}
if old.Cur >= desired {
return old.Cur, nil
}
if old.Max < desired {
limit := unix.Rlimit{
Cur: desired,
Max: desired,
}
err := unix.Setrlimit(unix.RLIMIT_NOFILE, &limit)
if err == nil {
return limit.Cur, nil
}
desired = old.Max
}
limit := unix.Rlimit{
Cur: desired,
Max: old.Max,
}
err = unix.Setrlimit(unix.RLIMIT_NOFILE, &limit)
if err != nil {
return old.Cur, err
}
return limit.Cur, nil
}