diff --git a/csgo/demo_loader.go b/csgo/demo_loader.go index 0d91e74..1b5db95 100644 --- a/csgo/demo_loader.go +++ b/csgo/demo_loader.go @@ -315,7 +315,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { if !d.GCReady { log.Infof("[DL] Postponing match %d (%s): GC not ready", demo.MatchId, demo.ShareCode) time.Sleep(5 * time.Second) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() d.parseDemo <- demo continue } @@ -323,7 +325,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { matchId, _, _, err := DecodeSharecode(demo.ShareCode) if err != nil || matchId == 0 { log.Warningf("[DL] Can't parse match with sharecode %s: %v", demo.ShareCode, err) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } @@ -334,7 +338,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { break default: log.Errorf("[DL] Failure trying to lookup match %d in db: %v", matchId, e) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } } else { @@ -346,19 +352,25 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { if err != nil { log.Warningf("[DL] Parsing demo from match %d failed: %v", demo.MatchId, err) } + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } log.Debugf("[DL] Skipped match %d: already parsed", matchId) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } matchDetails, err := d.getMatchDetails(demo.ShareCode) if err != nil { log.Warningf("[DL] Failure to get match-details for %d from GC: %v", demo.MatchId, err) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } @@ -392,7 +404,9 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { Save(context.Background()) if err != nil { log.Warningf("[DL] Unable to create match %d: %v", matchZero.GetMatchid(), err) + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() continue } @@ -473,6 +487,8 @@ func (d *DemoMatchLoader) gcWorker(apiKey string, rl ratelimit.Limiter) { if err != nil { log.Warningf("[DL] Can't queue demo %d for parsing: %v", demo.MatchId, err) } + d.parseMapL.Lock() delete(d.parseMap, demo.ShareCode) + d.parseMapL.Unlock() } }