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:
parent
bbe8b41fed
commit
18c1abd3e3
3 changed files with 24 additions and 12 deletions
|
@ -12,6 +12,7 @@ import (
|
|||
"net/url"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
@ -108,7 +109,13 @@ func SetupServerAndHandle(config *ConfigFile, serveMux *http.ServeMux) {
|
|||
logstasher.Setup(Configuration.ESServer, Configuration.ESIndexPrefix, Configuration.ESHostName)
|
||||
}
|
||||
|
||||
janitorsOnce.Do(func() {
|
||||
janitorsOnce.Do(startJanitors)
|
||||
}
|
||||
|
||||
// startJanitors starts the 'is_init_func' goroutines
|
||||
func startJanitors() {
|
||||
loadUniqueUsers()
|
||||
|
||||
go authorizationJanitor()
|
||||
go bunchCacheJanitor()
|
||||
go pubsubJanitor()
|
||||
|
@ -117,7 +124,6 @@ func SetupServerAndHandle(config *ConfigFile, serveMux *http.ServeMux) {
|
|||
|
||||
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
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue