mirror of
https://github.com/owncast/owncast.git
synced 2024-10-28 10:09:39 +01:00
fix(go): int64 -> uint64 for connection limit value
This commit is contained in:
parent
6cf93b98e1
commit
7a65e6d808
3 changed files with 6 additions and 6 deletions
|
@ -10,14 +10,14 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func setSystemConcurrentConnectionLimit(limit int64) {
|
func setSystemConcurrentConnectionLimit(limit uint64) {
|
||||||
var rLimit syscall.Rlimit
|
var rLimit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
originalLimit := rLimit.Cur
|
originalLimit := rLimit.Cur
|
||||||
rLimit.Cur = uint64(limit)
|
rLimit.Cur = limit
|
||||||
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ type Server struct {
|
||||||
// a map of user IDs and timers that fire for chat part messages.
|
// a map of user IDs and timers that fire for chat part messages.
|
||||||
userPartedTimers map[string]*time.Ticker
|
userPartedTimers map[string]*time.Ticker
|
||||||
seq uint
|
seq uint
|
||||||
maxSocketConnectionLimit int64
|
maxSocketConnectionLimit uint64
|
||||||
|
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
@ -215,7 +215,7 @@ func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Limit concurrent chat connections
|
// Limit concurrent chat connections
|
||||||
if int64(len(s.clients)) >= s.maxSocketConnectionLimit {
|
if uint64(len(s.clients)) >= s.maxSocketConnectionLimit {
|
||||||
log.Warnln("rejecting incoming client connection as it exceeds the max client count of", s.maxSocketConnectionLimit)
|
log.Warnln("rejecting incoming client connection as it exceeds the max client count of", s.maxSocketConnectionLimit)
|
||||||
_, _ = w.Write([]byte(events.ErrorMaxConnectionsExceeded))
|
_, _ = w.Write([]byte(events.ErrorMaxConnectionsExceeded))
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,14 +9,14 @@ import (
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getMaximumConcurrentConnectionLimit() int64 {
|
func getMaximumConcurrentConnectionLimit() uint64 {
|
||||||
var rLimit syscall.Rlimit
|
var rLimit syscall.Rlimit
|
||||||
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil {
|
||||||
log.Fatalln(err)
|
log.Fatalln(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
|
// Return the limit to 70% of max so the machine doesn't die even if it's maxed out for some reason.
|
||||||
proposedLimit := int64(float32(rLimit.Max) * 0.7)
|
proposedLimit := uint64(float32(rLimit.Max) * 0.7)
|
||||||
|
|
||||||
return proposedLimit
|
return proposedLimit
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue