1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-12 09:00:54 +00:00

Bugfixes: div0, wrong low-mem condition, race

This commit is contained in:
Kane York 2015-12-23 21:55:15 -08:00
parent bbe8b41fed
commit 18c1abd3e3
3 changed files with 24 additions and 12 deletions

View file

@ -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

View file

@ -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()
}

View file

@ -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)
}
}
}