Skip to content

chore(gateway): propagate request context in webRequestT - #6694

Merged
atzoum merged 3 commits into
rudderlabs:os.contribfrom
akshit-git24:fix/gateway-context-propagation
Mar 6, 2026
Merged

atzoum merged 3 commits into
rudderlabs:os.contribfrom
akshit-git24:fix/gateway-context-propagation

Conversation

@akshit-git24

@akshit-git24 akshit-git24 commented Feb 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

This PR fixes an issue where aggregate/batch requests in webRequestT were losing the original HTTP request context.

Previously, webRequestT did not store the context, causing the rate limiter and other downstream consumers to use context.TODO(). This prevented the gateway from respecting request cancellations and timeouts.

Changes:

  • Added ctx context.Context to the webRequestT struct.
  • Updated addToWebRequestQ in gateway/handle.go to capture req.Context().
  • Updated getJobDataFromRequest (consumer) to pass the propagated ctx to gw.rateLimiter.CheckLimitReached.

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

@ktgowtham
ktgowtham requested review from atzoum and mihir20 February 25, 2026 06:34
Comment thread gateway/handle.go Resolved
@akshit-git24

akshit-git24 commented Feb 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @atzoum ,
I've updated the rate limiter in gateway/handle.go . I resolved the feedback by ensuring we explicitly verify the context hasn't been canceled (req.ctx.Err() == nil) before proceeding to log the rate_limiter_error and increment the metrics counter."

Testing :
Added complete coverage in gateway/gateway_test.go focusing on con,text cancellation edge cases.
Test 1: Confirmed errRequestDropped is returned accurately when a user truly reaches the rate limit.
Test 2: Confirmed context.Canceled is returned successfully without incrementing stat counters when req.ctx gets canceled.
Test 3: Confirmed valid rate limit errors log their respective errors and metrics gracefully unhindered.
Validated tests run perfectly on Linux locally via go test.

Please let me know if there is any changes for enhancement.

Thank You!

@akshit-git24
akshit-git24 requested a review from atzoum February 26, 2026 16:04
@atzoum atzoum changed the title fix(gateway): propagate request context in webRequestT.Ensure ratelimiter and downstream components respect request cancellations. chore(gateway): propagate request context in webRequestT Mar 6, 2026
atzoum
atzoum approved these changes Mar 6, 2026 •
…miter and downstream components respect request cancellations.
… avoid stat increments on dropped connections and add tests.
@atzoum
atzoum force-pushed the fix/gateway-context-propagation branch from e1d33ec to 4d64f83 Compare March 6, 2026 12:32
🔒 Scanned for secrets using gitleaks 8.30.0
@atzoum

atzoum commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@akshit-git24 tests are failing

package=gateway make test

@atzoum
atzoum changed the base branch from master to os.contrib March 6, 2026 13:13
@atzoum
atzoum merged commit 964f2f9 into rudderlabs:os.contrib Mar 6, 2026
23 of 158 checks passed
@atzoum

atzoum commented Mar 6, 2026

Copy link
Copy Markdown
Contributor

@akshit-git24 I closed this pr by mistake, please open a new one

@akshit-git24

akshit-git24 commented Mar 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi @atzoum ,

I understand that the changes aren't finalized yet and the pr is merged. So in response to your last comment , i opened a new PR #6751 in the continuation of this PR.

Please Review the PR and mentor me if there is any type of enhancement or changes needed.

Thank You!

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