Skip to content

fix: respect context cancellation in gateway rate limiter - #6751

Merged
atzoum merged 5 commits into
rudderlabs:masterfrom
akshit-git24:fix/gateway-context-propagation
Mar 11, 2026
Merged

atzoum merged 5 commits into
rudderlabs:masterfrom
akshit-git24:fix/gateway-context-propagation

Conversation

@akshit-git24

@akshit-git24 akshit-git24 commented Mar 6, 2026 •

Copy link
Copy Markdown
Contributor

Description

Hi @atzoum @mihir20 ,

Continuation of #6694
This PR updates the gateway rate limiter in handle.go to propagate the request context (req.ctx) instead of context.TODO(), ensuring rate limit checks respect client disconnections. It also guards error logging and metric increments behind a req.ctx.Err() == nil check so that context cancellation errors are not mistakenly counted as rate limiter failures.

Changes

1.) gateway/handle.go : Pass req.ctx to CheckLimitReached. Only log rate_limiter_error and increment stats when the context is still active. Return req.ctx.Err() early if the context was cancelled.

2.) gateway/types.go : Add ctx context.Context field to webRequestT, populated from req.Context() in addToWebRequestQ.

3.) gateway/gateway_test.go: Add .AnyTimes() to the Subscribe mock to support nested Ginkgo contexts. Add AfterEach for gateway cleanup. Add 3 tests covering:

      i) errRequestDropped returned when rate limit is genuinely reached.
      ii) errRequestDropped returned when rate limit is genuinely reached.
      iii) Error logged and request allowed when rate limiter errors but context is active.

After this changes, my 3 test cases, which are failing is now running by using these commands :
1.) cd rudder-server/gateway
2.) go test -v -run='^TestGateway$' -ginkgo.focus='rate limit'

Please review the changes and let me know is there any changes for the enhancement.

Thank you

akshit-git24 and others added 5 commits March 6, 2026 14:31
…miter and downstream components respect request cancellations.
… avoid stat increments on dropped connections and add tests.
🔒 Scanned for secrets using gitleaks 8.30.0
…ests.Prevents panic on duplicate Subscribe calls in nested Ginkgo contexts.
@akshit-git24 akshit-git24 changed the title Fix/gateway context propagation fix: respect context cancellation in gateway rate limiter Mar 6, 2026
@atzoum
atzoum requested review from atzoum and mihir20 March 11, 2026 13:23
@atzoum
atzoum merged commit 589251a into rudderlabs:master Mar 11, 2026
22 of 121 checks passed
itsmihir pushed a commit that referenced this pull request Mar 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.70.0-rc.1](v1.69.0...v1.70.0-rc.1)
(2026-03-16)


### Features

* add a scheduled release cut workflow to cut release branches
([#6739](#6739))
([ab887ac](ab887ac))
* infer OAuth type from account definition when destination supports
accounts
([#6718](#6718))
([00d1755](00d1755))


### Bug Fixes

* false sanity check failure due to empty response
([#6762](#6762))
([0384603](0384603))
* gateway request blocked in store jobs blocking all other requests
([#6760](#6760))
([ca4d514](ca4d514))
* respect context cancellation in gateway rate limiter
([#6751](#6751))
([589251a](589251a))
* update prerelease branch versioning format in scheduled release
workflow
([#6745](#6745))
([fede9e4](fede9e4))


### Miscellaneous

* add check for pseudo-version dependencies in rudderlabs modules
([#6737](#6737))
([55ecd10](55ecd10))
* bump rudder-go-kit to 0.73.0
([#6753](#6753))
([1743f6b](1743f6b))
* remove gunicorn and add darwin compatibility
([#6742](#6742))
([392d1f4](392d1f4))
* use latest retryablehttp client
([#6754](#6754))
([629f036](629f036))
* user rudo docker image for partition migration integration tests
([#6757](#6757))
([5022fbd](5022fbd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
itsmihir pushed a commit that referenced this pull request Mar 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[1.70.0](v1.69.0...v1.70.0)
(2026-03-16)


### Features

* add a scheduled release cut workflow to cut release branches
([#6739](#6739))
([ab887ac](ab887ac))
* infer OAuth type from account definition when destination supports
accounts
([#6718](#6718))
([00d1755](00d1755))


### Bug Fixes

* false sanity check failure due to empty response
([#6762](#6762))
([0384603](0384603))
* gateway request blocked in store jobs blocking all other requests
([#6760](#6760))
([ca4d514](ca4d514))
* respect context cancellation in gateway rate limiter
([#6751](#6751))
([589251a](589251a))
* update prerelease branch versioning format in scheduled release
workflow
([#6745](#6745))
([fede9e4](fede9e4))


### Miscellaneous

* add check for pseudo-version dependencies in rudderlabs modules
([#6737](#6737))
([55ecd10](55ecd10))
* bump rudder-go-kit to 0.73.0
([#6753](#6753))
([1743f6b](1743f6b))
* remove gunicorn and add darwin compatibility
([#6742](#6742))
([392d1f4](392d1f4))
* use latest retryablehttp client
([#6754](#6754))
([629f036](629f036))
* user rudo docker image for partition migration integration tests
([#6757](#6757))
([5022fbd](5022fbd))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: rudderstack-github-actions[bot] <236995729+rudderstack-github-actions[bot]@users.noreply.github.com>
@github-actions
github-actions Bot deleted the fix/gateway-context-propagation branch May 7, 2026 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants