Skip to content

Split server start/wait/stop lifecycle - #648

Merged
SunSi12138 merged 1 commit into
mainfrom
issue-646-server-lifecycle
Sep 10, 2026
Merged

SunSi12138 merged 1 commit into
mainfrom
issue-646-server-lifecycle

Conversation

@SunSi12138

@SunSi12138 SunSi12138 commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Motivation

Fixes #646 by making Server lifecycle explicit and single-owner: startup, long-running serving, terminal waiting, and shutdown are no longer combined in public RunAsync.

Changes

  • Replace public RunAsync with StartAsync, WaitForShutdownAsync, and StopAsync as the only canonical Server lifecycle primitives.
  • Expose SharpLinkServerLifecycleState independently from HealthStatus.
  • Move accept-loop and Server-runtime background-task ownership/terminal failure handling into SharpLinkServer.
  • Keep per-connection and deferred-cleanup task failures inside their local failure domain: they remain observed/logged and joined during shutdown, but do not independently fault the whole Server.
  • Keep heartbeat-timeout connection cleanup inside the connection failure domain while retaining heartbeat-supervisor failure as terminal.
  • Make WaitForShutdownAsync a pure terminal observer; caller cancellation only cancels that wait.
  • Keep StopAsync as one shared Server-owned shutdown operation; caller cancellation does not cancel or force the shared drain.
  • Simplify Generic Host integration: no _runTask / _runCts; Host Start/Stop bridge directly to Server Start/Stop, with only a terminal observer for unexpected Server termination. Hosted Stop callers also only cancel their own wait.
  • Migrate demos, integration/AOT/load/chaos/package-smoke harnesses to the new primitives without adding a public compatibility shim.
  • Document lifecycle/readiness separation and add the Unreleased changelog entry.

Lifecycle semantics

  • StartAsync publishes Running only after the Server-owned accept operation has established its startup boundary; an immediate listener/accept failure is surfaced to the startup caller.
  • The built-in socket listener still performs bind/listen eagerly when the transport is constructed, so bind errors remain fail-fast before StartAsync; they are not deferred to a background task.
  • After startup, the accept supervisor and fatal Server-runtime tasks are owned and observed by SharpLinkServer; unrecoverable runtime failures converge on one terminal cleanup path and Faulted state.
  • Per-connection lifecycle/cleanup faults are observed without widening their failure domain to the whole Server.
  • Heartbeat timeout disconnects isolate/log connection cleanup failures at the per-connection boundary; other unhandled heartbeat-supervisor failures remain terminal.
  • WaitForShutdownAsync never initiates shutdown and completes/faults only when terminal cleanup is published.
  • StopAsync owns Draining -> Stopped/Faulted; all callers join the same operation and terminal failures are consistent with WaitForShutdownAsync.
  • StopAsync from Created produces a real terminal Stopped state; startup cancellation does not become a long-lived Server lifetime token after Running is published.

Validation

Final head: b3b372a45fb1baae1e1fa4ffe7e1145d644f0702 (single commit on current main).

  • PR Quick #2809: passed — Release build, Unit, Generator, LoadTest, Integration, AOT smoke, pack/package verification, demo/load/chaos smoke.
  • Release Gate [P1][Client] Deadline scan can target a reused PendingCall generation #560: passed — Linux, Windows, and macOS build/test matrices; Linux/Windows/macOS AOT; Linux/Windows/macOS chaos; pack/package smoke.
  • CodeQL #3846: passed.
  • Review follow-up: split tracked-task observation into non-terminal TrackFrameworkTask and terminal TrackServerRuntimeTask; per-connection/deferred cleanup keeps the local policy.
  • Heartbeat review follow-up: DisconnectHeartbeatTimedOutConnectionAsync isolates/logs heartbeat-timeout connection cleanup faults without downgrading the heartbeat supervisor itself.
  • Regression coverage: ConnectionCleanupFailureShouldNotTerminateServerRuntime and HeartbeatCleanupFailureShouldNotTerminateServerRuntime; both verify local cleanup failure does not terminate the Server, with the latter also proving accept continues after heartbeat cleanup failure.
  • Self-review: no Server public RunAsync compatibility entry remains; Generic Host has no run-loop CTS/task and no caller-cancellation ForceStop path; lifecycle coordination is isolated in SharpLinkServer.PublicLifecycle.cs; no temporary issue-646 workflow/script files remain in the PR tree.
  • API migration was cross-checked with [Runtime Architecture][Phase 18] 完成 public API/package 审计、发布门禁与迁移文档 #86: this is an intentional breaking lifecycle migration, with no long-lived legacy forwarding adapter.

@SunSi12138
SunSi12138 force-pushed the issue-646-server-lifecycle branch 3 times, most recently from 89fbb09 to 23bc348 Compare September 10, 2026 10:39
@SunSi12138
SunSi12138 marked this pull request as ready for review September 10, 2026 10:47

@SunSi12138 SunSi12138 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

整体 Start/Wait/Stop 分域、Host bridge 和 shared-stop cancellation 方向合理,exact-head Quick / Release Gate / CodeQL 也已通过。当前有一个 failure-domain blocker:本 PR 把共享 TrackFrameworkTask 中的所有异常都升级为 Server terminal failure,但该 tracker 同时承载 per-connection lifecycle task,而连接 cleanup 明确允许抛异常;这会让单个坏连接/transport cleanup 把整个 Server 置为 Faulted。见 inline。

Comment thread src/SharpLink.Server/SharpLinkServer.cs Outdated
@SunSi12138
SunSi12138 force-pushed the issue-646-server-lifecycle branch from 5e1a6c6 to 351992a Compare September 10, 2026 13:09
Replace public RunAsync with explicit StartAsync, WaitForShutdownAsync, and StopAsync ownership. Move accept/runtime supervision into SharpLinkServer, keep per-connection cleanup failures local including heartbeat-timeout cleanup, simplify Generic Host lifetime bridging, migrate repository callers, and document terminal failure semantics.

Fixes #646
@SunSi12138
SunSi12138 force-pushed the issue-646-server-lifecycle branch 3 times, most recently from 99b37d9 to b3b372a Compare September 10, 2026 13:44
@SunSi12138
SunSi12138 merged commit 8183ac2 into main Sep 10, 2026
42 checks passed
@SunSi12138
SunSi12138 deleted the issue-646-server-lifecycle branch September 10, 2026 13:51
SunSi12138 added a commit that referenced this pull request Sep 10, 2026
…cycle"

This reverts commit 8183ac2, restoring the first-parent tree at 9ba50b9.
SunSi12138 added a commit that referenced this pull request Sep 12, 2026
#677)

* Bump the testing group with 1 update

Bumps TUnit from 1.63.0 to 1.64.6

---
updated-dependencies:
- dependency-name: TUnit
  dependency-version: 1.64.6
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testing
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump github/codeql-action/init from 4.37.4 to 4.37.6

Bumps [github/codeql-action/init](https://github.com/github/codeql-action) from 4.37.4 to 4.37.6.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@f205ea1...5595cca)

---
updated-dependencies:
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.6
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(ci): pair CodeQL actions at 4.37.6

* Bump Microsoft.Extensions.DependencyInjection and 6 others

Bumps Microsoft.Extensions.DependencyInjection from 10.0.10 to 10.0.11
Bumps Microsoft.Extensions.DependencyInjection.Abstractions from 10.0.10 to 10.0.11
Bumps Microsoft.Extensions.Diagnostics.HealthChecks from 10.0.10 to 10.0.11
Bumps Microsoft.Extensions.Hosting from 10.0.10 to 10.0.11
Bumps Microsoft.Extensions.Logging to 10.0.11
Bumps Microsoft.Extensions.Logging.Abstractions from 10.0.10 to 10.0.11
Bumps Microsoft.Extensions.Logging.Console from 10.0.10 to 10.0.11

---
updated-dependencies:
- dependency-name: Microsoft.Extensions.DependencyInjection
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.DependencyInjection.Abstractions
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Diagnostics.HealthChecks
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Hosting
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Logging
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Logging
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Logging.Abstractions
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
- dependency-name: Microsoft.Extensions.Logging.Console
  dependency-version: 10.0.11
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: microsoft-extensions
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: bump version to 1.1.2

* Bump the testing group with 1 update

Bumps TUnit from 1.64.6 to 1.65.68

---
updated-dependencies:
- dependency-name: TUnit
  dependency-version: 1.65.68
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testing
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump github/codeql-action/analyze from 4.37.6 to 4.37.9

Bumps [github/codeql-action/analyze](https://github.com/github/codeql-action) from 4.37.6 to 4.37.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@5595cca...cdf488f)

---
updated-dependencies:
- dependency-name: github/codeql-action/analyze
  dependency-version: 4.37.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump github/codeql-action/init from 4.37.6 to 4.37.9

Bumps [github/codeql-action/init](https://github.com/github/codeql-action) from 4.37.6 to 4.37.9.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@5595cca...cdf488f)

---
updated-dependencies:
- dependency-name: github/codeql-action/init
  dependency-version: 4.37.9
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore(deps): bump Microsoft.CodeAnalysis.CSharp from 5.6.0 to 5.9.0

* Bump the roslyn group with 2 updates

Bumps Microsoft.CodeAnalysis.Analyzers from 5.6.0 to 5.9.0
Bumps Microsoft.CodeAnalysis.CSharp from 5.0.0 to 5.9.0

---
updated-dependencies:
- dependency-name: Microsoft.CodeAnalysis.Analyzers
  dependency-version: 5.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: roslyn
- dependency-name: Microsoft.CodeAnalysis.CSharp
  dependency-version: 5.9.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: roslyn
...

Signed-off-by: dependabot[bot] <support@github.com>

* Bump the testing group with 1 update

Bumps TUnit from 1.65.68 to 1.66.16

---
updated-dependencies:
- dependency-name: TUnit
  dependency-version: 1.66.16
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: testing
...

Signed-off-by: dependabot[bot] <support@github.com>

* Decouple client lifecycle from remote readiness

Introduce independent local lifecycle, readiness, and cluster state domains for single- and multi-cluster clients. Start hosted clients without blocking on remote availability, supervise initial connectivity recovery, preserve legacy explicit connection semantics, keep runtime Add/Replace candidates in the new child lifecycle, and prevent compatibility connection failures from tearing down an already-running coordinator.

Fixes #644

* Split server start, wait, and stop lifecycle

Replace public RunAsync with explicit StartAsync, WaitForShutdownAsync, and StopAsync ownership. Move accept/runtime supervision into SharpLinkServer, keep per-connection cleanup failures local including heartbeat-timeout cleanup, simplify Generic Host lifetime bridging, migrate repository callers, and document terminal failure semantics.

Fixes #646

* Revert "Merge pull request #648 from SunSi12138/issue-646-server-lifecycle"

This reverts commit 8183ac2, restoring the first-parent tree at 9ba50b9.

* Revert "Merge pull request #647 from SunSi12138/issue-644-client-lifecycle-readiness"

This reverts commit 9ba50b9, restoring the pre-accident main tree at 21ed74f.

* perf(client): observe unary emission within the send pump lifetime

* perf(runtime): batch ready timed requests at one emission boundary

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: sunsi <suns12138@163.com>
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.

[server][lifecycle] 拆分 Start/Wait/Stop 生命周期并移除 RunAsync

1 participant