Skip to content

Commit

Permalink
try timeout after wait
Browse files Browse the repository at this point in the history
  • Loading branch information
ClaytonNorthey92 committed Aug 22, 2024
1 parent 6b21809 commit 6ac1ca5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions service/bfg/bfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,21 @@ 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,
time.Duration(s.cfg.RequestTimeout)*time.Second)
defer cancel()

select {
case <-s.requestLimiter:
case <-parentCtx.Done():
log.Errorf("handleRequest parentContext done: %v", parentCtx.Err())
return
default:
log.Infof("Request limiter hit %v: %v", bws.addr, cmd)
<-s.requestLimiter
}
defer func() { s.requestLimiter <- true }()

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

start := time.Now()
defer func() {
s.metrics.rpcCallsDuration.With(prometheus.Labels{
Expand Down

0 comments on commit 6ac1ca5

Please sign in to comment.