Skip to content

Commit

Permalink
check for ctx.Done() when using request limiter (#244)
Browse files Browse the repository at this point in the history
when using the request limiter, ensure that we don't continue to wait on a context that is done

also need to use the request context
  • Loading branch information
ClaytonNorthey92 authored Sep 4, 2024
1 parent 64efe3f commit daa09d9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions service/bfg/bfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,20 @@ func (s *Server) handleRequest(parentCtx context.Context, bws *bfgWs, wsid strin
log.Tracef("handleRequest: %v", bws.addr)
defer log.Tracef("handleRequest exit: %v", bws.addr)

ctx, cancel := context.WithTimeout(parentCtx,
ctx, cancel := context.WithTimeout(bws.requestContext,
time.Duration(s.cfg.RequestTimeout)*time.Second)
defer cancel()

select {
case <-s.requestLimiter:
default:
log.Infof("Request limiter hit %v: %v", bws.addr, cmd)
<-s.requestLimiter
select {
case <-s.requestLimiter:
case <-ctx.Done():
log.Infof("request context done %v: %v", bws.addr, cmd)
return
}
}
defer func() { s.requestLimiter <- true }()

Expand Down

0 comments on commit daa09d9

Please sign in to comment.