Skip to content

fix: drain connection establishment during shutdown - #11263

Merged
ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-fix-drain-connection-establishment
Sep 15, 2026
Merged

ReubenBond merged 2 commits into
dotnet:mainfrom
ReubenBond:rb-fix-drain-connection-establishment

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Sep 15, 2026 •

Copy link
Copy Markdown
Member

Problem

Shutdown can observe an empty routing table while an accepted asynchronous acquisition is waiting to publish its pending attempt. Initialization failure can also clear routing state while the connection runner is still executing middleware cleanup, allowing resource disposal before accepted work finishes.

Solution

Use the existing internal AdmissionGate to own acquisition before its first yield through successful publication or failure cleanup. Outbound silo preamble publication remains under that original ownership; listener-owned inbound publication takes its own synchronous admission. Close admission before canceling attempts and signaling connections to terminate, then drain producers and rescan their final publications.

Track outbound runners independently from routing entries and join the runner after failed initialization. Keep shutdown cancellation resources valid through producer and runner cleanup, including when a canceled host stop abandons its wait. Preserve listener accept-loop ownership and the listener's same-stage dependency on ConnectionManager.Closed.

Connection closure atomically orders queued middleware startup against shutdown, aborts the original transport even during TLS or Orleans-preamble initialization, and waits for middleware to unwind before disposing the connection context. This lets TLS restore its original transport before socket disposal joins the underlying I/O tasks. Middleware completion is signaled before the runner awaits the shared close task.

Preserve pending-attempt coalescing, fast reuse, retry backoff, and endpoint-specific closure. Focused regressions exercise unpublished admission, late creation, production SiloConnection preamble publication, initialization failure/cancellation, a wrapped-stream initialization timeout with controlled cleanup, canceled host waits, coalescing/reuse, inbound rejection, and pre-start/synchronous middleware failure. The networking implementation guide describes these ownership guarantees.

Independent of reminder and observer shutdown changes; no shared gate API, listener stage, or lifecycle adapter changes.

Microsoft Reviewers: Open in CodeFlow

Copilot AI lite review requested due to automatic review settings September 15, 2026 20:16

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review tier: Lite
Findings: None

What changed in this PR

Improves connection shutdown by draining in-flight establishment and cleanup before resource disposal.

Changes:

  • Adds admission gating and runner tracking.
  • Handles queued and failed connection cleanup safely.
  • Adds lifecycle regression tests and documentation.
File Description
test/​Orleans.Core.Tests/​Networking/​ConnectionManagerTests.cs Adds shutdown and connection lifecycle regression tests.
src/​Orleans.Core/​Networking/​ConnectionManager.cs Coordinates admission, publication, runner cleanup, and shutdown draining.
src/​Orleans.Core/​Networking/​Connection.cs Safely handles queued closure and transport cleanup.
docs/​site/​src/​content/​docs/​implementation/​messaging-networking.md Documents connection ownership and shutdown guarantees.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI review requested due to automatic review settings September 15, 2026 20:30
@ReubenBond
ReubenBond marked this pull request as ready for review September 15, 2026 20:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The shutdown and lifecycle changes require final human review.

Review tier: Lite
Findings: None

@github-actions

Copy link
Copy Markdown
Contributor

Code coverage

Metric Pull request Current main Variance
Lines 81.71% (110,469 / 135,197) 81.70% (110,404 / 135,131) +0.0082 pp
Branches 70.64% (31,403 / 44,458) 70.63% (31,386 / 44,440) +0.0096 pp

Report-only conclusion: improved.

The current-main baseline is commit 4fa1669074 and uses the same reviewed coverage matrix.

Coverage combines every CI test matrix job, including providers, CodeGen, .NET 8/10, Linux, Windows, and macOS, using canonical physical source and branch identities.

The comparison remains report-only while normal line and branch variance is calibrated.

Coverage details

@ReubenBond
ReubenBond merged commit 437bb05 into dotnet:main Sep 15, 2026
73 checks passed
@ReubenBond
ReubenBond deleted the rb-fix-drain-connection-establishment branch September 15, 2026 21:26
This was referenced Oct 12, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants