Skip to content

Add RESTORING database filter to waiting_tasks collector (#430)#434

Merged
erikdarlingdata merged 1 commit intodevfrom
fix/waiting-tasks-mirror-safety
Mar 5, 2026
Merged

Add RESTORING database filter to waiting_tasks collector (#430)#434
erikdarlingdata merged 1 commit intodevfrom
fix/waiting-tasks-mirror-safety

Conversation

@erikdarlingdata
Copy link
Owner

Summary

  • Add d.state = 0 filter to the sys.databases join in the waiting_tasks collector
  • Prevents sessions in RESTORING databases (mirroring passive / AG secondary) from being passed to sys.dm_exec_sql_text and sys.dm_exec_text_query_plan
  • Matches the pattern already applied to query_stats, procedure_stats, query_store, and file_io_stats collectors in PR Fix SQL dumps on mirroring passive servers #385

Context

Issue #430 reported SQL dumps on a mirroring passive server. WinDbg analysis of the dumps showed the crashes are from an internal SQL Server 2016 background thread (spid 40, m_fBackground=1), not from our collectors. However, the waiting_tasks collector was the only one still missing the RESTORING database guard — this closes that gap.

Test plan

  • One-line change: adds AND d.state = 0 to the LEFT JOIN condition
  • Pattern matches existing guards in other collectors

🤖 Generated with Claude Code

The waiting_tasks collector joins sys.databases without filtering
d.state = 0 (ONLINE), which means sessions running in the context
of a RESTORING database (mirroring passive/AG secondary) can pass
through to sys.dm_exec_sql_text and sys.dm_exec_text_query_plan.

While the dumps in #430 turned out to be an internal SQL Server 2016
background thread crash (not our collector), this hardens the
waiting_tasks collector to match the pattern already used in
query_stats, procedure_stats, query_store, and file_io_stats
collectors (PR #385).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@erikdarlingdata erikdarlingdata merged commit 44e5961 into dev Mar 5, 2026
7 checks passed
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