Skip to content

Extract shared single-flight teardown helper - #11486

Merged
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/duplicate-code-single-flight-pattern
Sep 24, 2026
Merged

Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/duplicate-code-single-flight-pattern

Conversation

Copilot AI commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Server-mode client types duplicated the lock-and-cache pattern used to coordinate concurrent teardown requests. This made the idempotency guarantee easy to change inconsistently.

  • Shared teardown coordination

    • Add SingleFlightTask to schedule an action once and return the same task to every caller.
    • Support synchronous and asynchronous teardown delegates.
  • Client adoption

    • Replace duplicated shutdown locks and cached tasks in MtpServerClient, MtpServerProcess, and MtpServerInProcessHost.
    • Keep the in-process host’s read-loop flag update outside the shared helper.
  • Coverage

    • Add concurrent-call tests covering task identity and exactly-once execution for both delegate forms.
private readonly SingleFlightTask _shutdown = new();

private Task StartShutdownAsync()
    => _shutdown.StartAsync(ShutdownCore);

Copilot AI balanced review requested due to automatic review settings September 24, 2026 07:09

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 wasn't able to review any files in this pull request.


💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 24, 2026 07:18
Copilot AI changed the title [WIP] Refactor duplicate single-flight teardown patterns in Client types Extract shared single-flight teardown helper Sep 24, 2026

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

🟡 Changes recommended

The new test uses non-generic TaskCompletionSource, which prevents the Windows net462 target from compiling.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 24, 2026
@github-actions github-actions Bot removed the state/needs-review Awaiting review from the team. label Sep 24, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review September 24, 2026 07:52
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Sep 24, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 24, 2026 08:04
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 24, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 24, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Sep 24, 2026

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

The refactor preserves existing teardown semantics and is adequately covered across both delegate forms.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@microsoft-github-policy-service microsoft-github-policy-service Bot removed the state/needs-review Awaiting review from the team. label Sep 24, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Sep 24, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Sep 24, 2026
@Evangelink
Amaury Levé (Evangelink) merged commit 260b2e7 into main Sep 24, 2026
38 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/duplicate-code-single-flight-pattern branch September 24, 2026 09:30
@microsoft-github-policy-service microsoft-github-policy-service Bot removed the state/approved Proposal approved; ready for implementation. label Sep 24, 2026
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.

[duplicate-code] Duplicate Code: Single-Flight Teardown Pattern Repeated in ServerMode.Client Types

4 participants