fix race condition on 43 msg creation/closure. Speed up game object insert to db (from 10-12s to 1-2s)

This commit is contained in:
lbenedar
2026-04-27 17:29:15 +03:00
parent 4bb4b04004
commit 5a77a6ee0f
39 changed files with 261 additions and 146 deletions

View File

@@ -64,25 +64,26 @@ func NewFoundryTransport(data *FoundryTransportData) *FoundryTransport {
}
}
func (t *FoundryTransport) CloseMsgChannel(id int, timeout time.Duration) bool {
func (t *FoundryTransport) CloseMsgChannel(msgChan chan []byte, id int, timeout time.Duration) bool {
time.Sleep(timeout)
t.ChanMutex.Lock()
defer t.ChanMutex.Unlock()
ok := true
if _, ok = t.ExchangeChan.Msgs[id]; !ok {
return false
}
select {
case _, ok = <-t.ExchangeChan.Msgs[id]:
case _, ok = <-msgChan:
if ok {
close(t.ExchangeChan.Msgs[id])
delete(t.ExchangeChan.Msgs, id)
if msgChan == t.ExchangeChan.Msgs[id] {
delete(t.ExchangeChan.Msgs, id)
}
close(msgChan)
}
default:
close(t.ExchangeChan.Msgs[id])
delete(t.ExchangeChan.Msgs, id)
if msgChan == t.ExchangeChan.Msgs[id] {
delete(t.ExchangeChan.Msgs, id)
}
close(msgChan)
}
return ok