Skip to content

Thread cancellation through 5 PostgreSQL web reads (#4203) - #4409

Merged
erikdarlingdata merged 3 commits into
devfrom
fix/4203-web-read-cancellation-14
Sep 26, 2026
Merged

erikdarlingdata merged 3 commits into
devfrom
fix/4203-web-read-cancellation-14

Conversation

@erikdarlingdata

@erikdarlingdata erikdarlingdata commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

Refs #4203.

Why

An abandoned web request for a PostgreSQL-target read still ran its store query to completion, because these five tools took no CancellationToken and could not stop a query the caller had already given up on.

What changes

Five tools under Darling/PerformanceMonitor.Darling.Service/Mcp/ now take a trailing CancellationToken cancellationToken = default and pass it into every store call they make (resolver, coverage/precondition checks, the row reads, not-collected status), following the pattern of #4357/#4359:

  • DarlingMcpPgIndexTools.cs — get_pg_index_bloat, get_pg_column_stats
  • DarlingMcpPgCpuUtilizationTools.cs — get_pg_cpu_utilization
  • DarlingMcpPgLogEventTools.cs — get_pg_log_events
  • DarlingMcpPgLoggingAuditTools.cs — get_pg_logging_audit

Each tool's catch block is narrowed to when (ex is not OperationCanceledException). All five storage-layer methods these tools call already accepted a CancellationToken parameter, so no shared-helper signature changed.

The five tools are removed from DarlingWebEndpoints.CancellationAllowlist, and their dispatch entries now pass cancellationToken: c.RequestAborted (or the equivalent positional argument for the get_pg_cpu_utilization/get_pg_index_bloat/get_pg_column_stats/get_pg_log_events calls).

Lite: N/A, no /api/read surface exposes these tools.

Test plan

  • dotnet build Darling/Darling.Tests/Darling.Tests.csproj -p:EnableWindowsTargeting=true — 0 warnings-relevant errors, 0 errors.
  • dotnet build Lite.Tests/Lite.Tests.csproj -p:EnableWindowsTargeting=true — 0 errors (both build-only on macOS; Windows-only, CI decides them at runtime).
  • Ran WebReadCancellationPinTests in-process on macOS: Total: 127, Errors: 0, Failed: 0. This is a reflection ratchet over every non-allowlisted dispatch entry (EveryStoreReadingToolMethod_TakesACancellationToken_UnlessAllowlisted, CancellationAllowlist_HasNoStaleEntry); before this change these 5 tools were still on the allowlist with no CancellationToken parameter, so the ratchet passed them by construction (RED case: had one of the five been removed from the allowlist without adding the parameter and dispatch argument, EveryStoreReadingToolMethod_TakesACancellationToken_UnlessAllowlisted would fail on that dispatch entry for dropping c.RequestAborted).
  • Also ran PgTargetMcpSurfaceTests (3/3), McpServiceParameterDiSeatCensusTests (1/1) in-process — both green. EngineCapabilityMissTests and RuntimePreconditionMissTests were not found as test classes in this assembly (0 discovered), so nothing to run there.

CHANGELOG entry

SECTION: Fixed
ENTRY:

get_pg_index_bloat, get_pg_column_stats, get_pg_cpu_utilization, get_pg_log_events and get_pg_logging_audit now take a CancellationToken and pass it to every store call, so an abandoned web request stops its query instead of running to completion. Removes the five from CancellationAllowlist.
@erikdarlingdata
erikdarlingdata marked this pull request as ready for review September 26, 2026 13:34
@erikdarlingdata
erikdarlingdata merged commit 6a585e0 into dev Sep 26, 2026
15 of 16 checks passed
@erikdarlingdata
erikdarlingdata deleted the fix/4203-web-read-cancellation-14 branch September 26, 2026 13:34
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.

1 participant