From daa09d93859dacbe0ab4552f2f63c897b56ad43c Mon Sep 17 00:00:00 2001 From: ClaytonNorthey92 Date: Wed, 4 Sep 2024 12:39:01 -0400 Subject: [PATCH] check for ctx.Done() when using request limiter (#244) 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 --- service/bfg/bfg.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/service/bfg/bfg.go b/service/bfg/bfg.go index b0f460eb..02744494 100644 --- a/service/bfg/bfg.go +++ b/service/bfg/bfg.go @@ -271,7 +271,7 @@ 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() @@ -279,7 +279,12 @@ func (s *Server) handleRequest(parentCtx context.Context, bws *bfgWs, wsid strin 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 }()