Skip to content

fix(router): drain only in-flight requests of muxes the graph server tears down#3064

Merged
endigma merged 2 commits into
mainfrom
jesse/router-18-drain-bug
Jul 13, 2026
Merged

fix(router): drain only in-flight requests of muxes the graph server tears down#3064
endigma merged 2 commits into
mainfrom
jesse/router-18-drain-bug

Conversation

@endigma

@endigma endigma commented Jul 9, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Bug Fixes
    • Improved shutdown and reload behavior so in-flight requests are tracked correctly during graph swaps.
    • Ensured the system waits only for requests owned by the server being shut down, while allowing reused request handlers to continue across reloads.
    • Added coverage for a shutdown scenario involving blocked requests, reloads, and configuration/version consistency.

@endigma endigma requested a review from a team as a code owner July 9, 2026 14:17
@github-actions github-actions Bot added the router label Jul 9, 2026
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-9a44b1f4b0ff4a325fb94afe95f0d070e8b1df4a-nonroot

@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f47103da-2ec5-46b7-a860-2b109800924c

📥 Commits

Reviewing files that changed from the base of the PR and between 6c2dc0f and 0f2d926.

📒 Files selected for processing (3)
  • router-tests/lifecycle/shutdown_test.go
  • router/core/graph_server.go
  • router/core/graph_server_test.go
💤 Files with no reviewable changes (1)
  • router/core/graph_server_test.go

Walkthrough

This change moves in-flight request tracking from the graphServer level to individual graphMux instances, adding a per-mux atomic counter and an inFlightOwnedRequests helper that skips reused muxes during shutdown waits. Tests are updated and a new hot-reload shutdown test with a blocking middleware module is added.

Changes

Mux-owned in-flight tracking and shutdown wait

Layer / File(s) Summary
Per-mux counter field
router/core/graph_server.go
Removes the server-level inFlightRequests field and its initialization, adding a per-graphMux atomic.Int64 counter documented as owned by the mux, not drained when reused.
Request counting and shutdown wait logic
router/core/graph_server.go
GraphQL request handling now increments/decrements the mux-level counter; a new inFlightOwnedRequests() sums counters across non-reused muxes; shutdown wait now checks this aggregate instead of the removed server-level counter.
Unit test literal updates
router/core/graph_server_test.go
Removes the now-obsolete inFlightRequests field initialization from graphServer literals in existing shutdown subtests.
Blocking middleware and hot-reload shutdown test
router-tests/lifecycle/shutdown_test.go
Adds a header-driven blocking middleware module and TestGraphServerShutdown, verifying that shutdown waits on the old server's torn-down mux request while a reused mux continues serving a blocked request after reload.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • wundergraph/cosmo#2838: Both PRs adjust shutdown/swap behavior in graph_server.go to special-case reused graphMux instances and add related swap tests.
  • wundergraph/cosmo#3035: Both PRs modify reused-mux reload/shutdown lifecycle semantics and corresponding TestGraphServerShutdown coverage in the same file.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main router draining behavior change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 golangci-lint (2.12.2)

level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies"


Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.89%. Comparing base (31d1baf) to head (314d6f4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3064      +/-   ##
==========================================
+ Coverage   61.85%   61.89%   +0.03%     
==========================================
  Files         261      261              
  Lines       30649    30657       +8     
==========================================
+ Hits        18958    18974      +16     
+ Misses      10179    10173       -6     
+ Partials     1512     1510       -2     
Files with missing lines Coverage Δ
router/core/graph_server.go 85.51% <100.00%> (+0.07%) ⬆️

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@endigma endigma force-pushed the jesse/router-18-drain-bug branch from 0f2d926 to 314d6f4 Compare July 13, 2026 09:33
@endigma endigma merged commit 076b5b3 into main Jul 13, 2026
36 checks passed
@endigma endigma deleted the jesse/router-18-drain-bug branch July 13, 2026 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants