Skip to content

Review sync-over-async and cancellation gaps in server, worker, and database APIs #4059

Description

@Widthdom

Summary

The dogfood .NET risk audits found several sync-over-async and cancellation-token-none paths. Some are likely compatibility wrappers, but they should be documented, narrowed, or converted where practical.

Evidence

Observed categories include:

  • cancellation-token-none on public/sync database convenience overloads such as DbWriter.BeginTransaction() and related write helpers.
  • sync-over-async in paths such as McpServer.ProcessFrame, LspServer.Run, GitHelper.RunProcessCapturingResult, SymbolExtractionWorker.Invoke / WaitForTask, post-extraction hook callback worker, console UI, issue duplicate preflight, and suggestion-store boundaries.

Additional dogfood distribution:

  • dotnet-risk-patterns/cancellation-token-none found 32 hits in 17 production files.
  • Top files: McpServer (5), DbWriter (4), DiffCommandRunner (3), ExportImportCommandRunner (3), HttpMcpTransport (3), DbContext (2), LspServer (2).
  • Other files include DbCommandRunner, GitHelper, IndexCommandRunner.FullScan, IndexCommandRunner.UpdateTargets, IssueDuplicatePreflight, QueryCommandRunner, SuggestionStore, DbReader, BackgroundTaskObserver, and AuditLogSink.
  • dotnet-risk-patterns/sync-over-async found 17 hits in 9 production files. Top files include ProgramRunner, McpServer, hook callback worker, symbol extraction worker, and LspServer.

Why it matters

For CLI tools these patterns may be acceptable in narrow places, but server/worker/database paths can become long-running. Non-cancellable or sync-blocked paths increase the chance of hangs, shutdown delays, starvation, or hidden timeout behavior.

Acceptance criteria

  • Classify each production hit as intentional compatibility API, process/CLI boundary, test-only helper, or fix-needed path.
  • Convert fix-needed paths to async/cancellable flow.
  • Add comments or docs for intentionally retained sync wrappers.
  • Add tests where behavior changes, especially cancellation and shutdown behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions