fix(backend): removed mini ddos of sessions with negative duration

This commit is contained in:
Alexander Zavorotynskiy 2023-07-31 15:48:25 +04:00
parent 9d7cc4935d
commit 900a25993f

View file

@ -94,6 +94,7 @@ func main() {
case <-tick:
failedSessionEnds := make(map[uint64]uint64)
duplicatedSessionEnds := make(map[uint64]uint64)
negativeDuration := make(map[uint64]uint64)
// Find ended sessions and send notification to other services
sessionEndGenerator.HandleEndedSessions(func(sessionID uint64, timestamp uint64) bool {
@ -109,6 +110,10 @@ func main() {
failedSessionEnds[sessionID] = timestamp
return true
}
if strings.Contains(err.Error(), "is less than zero for uint64") {
negativeDuration[sessionID] = timestamp
return true
}
log.Printf("can't save sessionEnd to database, sessID: %d, err: %s", sessionID, err)
return false
}
@ -138,6 +143,9 @@ func main() {
if len(duplicatedSessionEnds) > 0 {
log.Println("session end duplicates:", duplicatedSessionEnds)
}
if len(negativeDuration) > 0 {
log.Println("sessions with negative duration:", negativeDuration)
}
producer.Flush(cfg.ProducerTimeout)
if err := consumer.CommitBack(intervals.EVENTS_BACK_COMMIT_GAP); err != nil {
log.Printf("can't commit messages with offset: %s", err)