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