Skip to content

fix(router): make HTTPConnector and NIXLConnector stateless to prevent data races and request corruption - #1657

Open
bhuvan-somisetty wants to merge 1 commit into
volcano-sh:mainfrom
bhuvan-somisetty:fix/stateless-connectors-data-race-1656
Open

fix(router): make HTTPConnector and NIXLConnector stateless to prevent data races and request corruption#1657
bhuvan-somisetty wants to merge 1 commit into
volcano-sh:mainfrom
bhuvan-somisetty:fix/stateless-connectors-data-race-1656

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

In HTTPConnector (pkg/kthena-router/connectors/http.go) and NIXLConnector (pkg/kthena-router/connectors/nixl.go), mutable per-request state (prefillRequest, decodeRequest, and decodeRequestBody) were maintained as struct fields on the connector instances.

When Kthena Router operates in PD disaggregation mode, connector singletons created via r.connectorFactory.GetConnector(connectorType) are shared across concurrent requests. When two or more requests are routed through HTTPConnector, NIXLConnector, or MoonCakeConnector concurrently, multiple goroutines concurrently mutate and read h.decodeRequest, h.prefillRequest, n.prefillRequest, and n.decodeRequestBody on the shared connector instance without synchronization. This causes a data race and request payload corruption, where one request's decode phase sends another concurrent request's prompt and parameters to the decode engine.

This PR makes HTTPConnector and NIXLConnector completely stateless by:

  1. Removing per-request struct fields (prefillRequest, decodeRequest, decodeRequestBody) from HTTPConnector and NIXLConnector.
  2. Maintaining request objects as local variables within Proxy() and passing them directly into prefill() and decode().
  3. Adding concurrent regression unit tests (TestHTTPConnector_ConcurrentThreadSafety and TestNIXLConnector_ConcurrentThreadSafety) that simulate concurrent requests through a shared connector instance to verify thread safety and payload isolation.

Which issue(s) this PR fixes:

Fixes #1656

Bug evidence (required for bug-related PRs):

Special notes for your reviewer:

All unit tests in pkg/kthena-router/... pass cleanly.

Does this PR introduce a user-facing change?:

NONE

@volcano-sh-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign lizhencheng9527 for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/stateless-connectors-data-race-1656 branch from 945c71f to c210031 Compare August 20, 2026 12:58
HTTPConnector and NIXLConnector stored mutable per-request state (prefillRequest, decodeRequest, and decodeRequestBody) as fields on the connector structs. In PD disaggregation mode, connector singletons are shared across concurrent requests, leading to data races and request cross-talk under concurrency where one request's decode payload would be overwritten by another concurrent request.

Make HTTPConnector and NIXLConnector stateless by maintaining prefill and decode request objects as local variables within Proxy, and add concurrent regression tests verifying thread safety.

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
@bhuvan-somisetty
bhuvan-somisetty force-pushed the fix/stateless-connectors-data-race-1656 branch from c210031 to d5427f5 Compare August 23, 2026 00:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Accepted

Development

Successfully merging this pull request may close these issues.

bug(router): HTTPConnector and NIXLConnector store per-request state on connector struct, causing data races and request corruption under concurrency

2 participants