Skip to content

Commit

Permalink
fix(gateway): send on closed chan - (*Handle).webRequestQ (#4709)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidddddarth authored Jul 18, 2024
1 parent aab477b commit d857284
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions gateway/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ type Handle struct {
// other state

backendConfigInitialised bool
inFlightRequests *sync.WaitGroup

trackCounterMu sync.Mutex // protects trackSuccessCount and trackFailureCount
trackSuccessCount int
Expand Down
11 changes: 11 additions & 0 deletions gateway/handle_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"net/http/httputil"
"net/url"
"strconv"
"sync"
"time"

"github.com/rudderlabs/rudder-schemas/go/stream"
Expand Down Expand Up @@ -68,6 +69,7 @@ func (gw *Handle) Setup(
gw.versionHandler = versionHandler
gw.rsourcesService = rsourcesService
gw.sourcehandle = sourcehandle
gw.inFlightRequests = new(sync.WaitGroup)

// Port where GW is running
gw.conf.webPort = config.GetIntVar(8080, 1, "Gateway.webPort")
Expand Down Expand Up @@ -389,6 +391,13 @@ func (gw *Handle) StartWebHandler(ctx context.Context) error {
gw.logger.Child("rsources_failed_keys"),
)
srvMux.Use(
func(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gw.inFlightRequests.Add(1)
h.ServeHTTP(w, r)
gw.inFlightRequests.Done()
})
},
chiware.StatMiddleware(ctx, stats.Default, component),
middleware.LimitConcurrentRequests(gw.conf.maxConcurrentRequests),
middleware.UncompressMiddleware,
Expand Down Expand Up @@ -488,6 +497,8 @@ func (gw *Handle) Shutdown() error {
return err
}

gw.inFlightRequests.Wait()

// UserWebRequestWorkers
for _, worker := range gw.userWebRequestWorkers {
close(worker.webRequestQ)
Expand Down

0 comments on commit d857284

Please sign in to comment.