From 7a65e6d808ffe70223a85db3a3610508fa8d5dc7 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Tue, 17 Sep 2024 08:11:35 -0700 Subject: [PATCH] fix(go): int64 -> uint64 for connection limit value --- core/chat/concurrentConnections.go | 4 ++-- core/chat/server.go | 4 ++-- core/chat/utils.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/chat/concurrentConnections.go b/core/chat/concurrentConnections.go index cbbea81c3..3fd18a26e 100644 --- a/core/chat/concurrentConnections.go +++ b/core/chat/concurrentConnections.go @@ -10,14 +10,14 @@ import ( log "github.com/sirupsen/logrus" ) -func setSystemConcurrentConnectionLimit(limit int64) { +func setSystemConcurrentConnectionLimit(limit uint64) { var rLimit syscall.Rlimit if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { log.Fatalln(err) } originalLimit := rLimit.Cur - rLimit.Cur = uint64(limit) + rLimit.Cur = limit if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { log.Fatalln(err) } diff --git a/core/chat/server.go b/core/chat/server.go index 771abdc9d..29b4ccffc 100644 --- a/core/chat/server.go +++ b/core/chat/server.go @@ -41,7 +41,7 @@ type Server struct { // a map of user IDs and timers that fire for chat part messages. userPartedTimers map[string]*time.Ticker seq uint - maxSocketConnectionLimit int64 + maxSocketConnectionLimit uint64 mu sync.RWMutex } @@ -215,7 +215,7 @@ func (s *Server) HandleClientConnection(w http.ResponseWriter, r *http.Request) } // 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) _, _ = w.Write([]byte(events.ErrorMaxConnectionsExceeded)) return diff --git a/core/chat/utils.go b/core/chat/utils.go index fae7beb29..8f0c79fc2 100644 --- a/core/chat/utils.go +++ b/core/chat/utils.go @@ -9,14 +9,14 @@ import ( log "github.com/sirupsen/logrus" ) -func getMaximumConcurrentConnectionLimit() int64 { +func getMaximumConcurrentConnectionLimit() uint64 { var rLimit syscall.Rlimit if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit); err != nil { 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. - proposedLimit := int64(float32(rLimit.Max) * 0.7) + proposedLimit := uint64(float32(rLimit.Max) * 0.7) return proposedLimit }