diff --git a/socketserver/server/handlecore.go b/socketserver/server/handlecore.go index 6e5ced54..1be2ef9c 100644 --- a/socketserver/server/handlecore.go +++ b/socketserver/server/handlecore.go @@ -12,6 +12,7 @@ import ( "net/url" "os" "os/signal" + "runtime" "strconv" "strings" "sync" @@ -108,16 +109,21 @@ func SetupServerAndHandle(config *ConfigFile, serveMux *http.ServeMux) { logstasher.Setup(Configuration.ESServer, Configuration.ESIndexPrefix, Configuration.ESHostName) } - janitorsOnce.Do(func() { - go authorizationJanitor() - go bunchCacheJanitor() - go pubsubJanitor() - go aggregateDataSender() - go commandCounter() + janitorsOnce.Do(startJanitors) +} - go ircConnection() - go shutdownHandler() - }) +// startJanitors starts the 'is_init_func' goroutines +func startJanitors() { + loadUniqueUsers() + + go authorizationJanitor() + go bunchCacheJanitor() + go pubsubJanitor() + go aggregateDataSender() + go commandCounter() + + go ircConnection() + go shutdownHandler() } func shutdownHandler() { @@ -169,7 +175,7 @@ func HTTPHandleRootURL(w http.ResponseWriter, r *http.Request) { if r.Header.Get("Connection") == "Upgrade" { updateSysMem() - if Statistics.SysMemTotalKB-Statistics.SysMemFreeKB < Configuration.MinMemoryKBytes { + if Statistics.SysMemFreeKB > 0 && Statistics.SysMemFreeKB < Configuration.MinMemoryKBytes { atomic.AddUint64(&Statistics.LowMemDroppedConnections, 1) w.WriteHeader(503) return diff --git a/socketserver/server/stats.go b/socketserver/server/stats.go index 7ba62f1b..d9fb11f3 100644 --- a/socketserver/server/stats.go +++ b/socketserver/server/stats.go @@ -122,7 +122,7 @@ func updatePeriodicStats() { Statistics.CpuUsagePct = 100 * float64(userTicks+sysTicks) / (timeDiff.Seconds() * float64(ticksPerSecond)) Statistics.MemoryRSSKB = uint64(pstat.Rss * pageSize / 1024) - Statistics.MemPerClientBytes = (Statistics.MemoryRSSKB * 1024) / Statistics.CurrentClientCount + Statistics.MemPerClientBytes = (Statistics.MemoryRSSKB * 1024) / (Statistics.CurrentClientCount + 1) } updateSysMem() } diff --git a/socketserver/server/testinfra_test.go b/socketserver/server/testinfra_test.go index 0c1e6a03..e2c1abef 100644 --- a/socketserver/server/testinfra_test.go +++ b/socketserver/server/testinfra_test.go @@ -95,6 +95,7 @@ type TBackendRequestChecker struct { currentRequest int tb TBC + mutex sync.Mutex } func NewTBackendRequestChecker(tb TBC, urls ...TExpectedBackendRequest) *TBackendRequestChecker { @@ -102,6 +103,9 @@ func NewTBackendRequestChecker(tb TBC, urls ...TExpectedBackendRequest) *TBacken } func (backend *TBackendRequestChecker) ServeHTTP(w http.ResponseWriter, r *http.Request) { + backend.mutex.Lock() + defer backend.mutex.Unlock() + if r.Method != MethodIsPost { backend.tb.Errorf("Bad backend request: was not a POST. %v", r) return @@ -129,7 +133,9 @@ func (backend *TBackendRequestChecker) ServeHTTP(w http.ResponseWriter, r *http. } else if len(v) == 0 { headers.Del(k) } else { - for _, hv := range v { headers.Add(k, hv) } + for _, hv := range v { + headers.Add(k, hv) + } } }