How to fix Error 522 on Windows Server 2025 / Windows 11

Troubleshooting Guide: SQL Server Error 522 — “The WAITFOR Thread Was Evicted”

Why This Error Happens

This error occurs when SQL Server’s scheduler forcibly evicts a worker thread that is executing a WAITFOR statement, typically because the system is under severe memory or scheduler pressure. It commonly happens when SQLOS needs to reclaim threads for higher-priority tasks, when the max worker thread pool is exhausted, or when a resource governor limit is being enforced. Corrupted or misconfigured tempdb files and insufficient memory allocation for SQL Server on Windows Server 2025 can also trigger this eviction behavior.

Step-by-Step Resolution Guide

Step 1: Check SQL Server Error Logs and Scheduler Health

  • Open SQL Server Management Studio (SSMS) and run:
  EXEC sp_readerrorlog 0, 1, 'WAITFOR';
  • Review C:\Program Files\Microsoft SQL Server\MSSQL17.MSSQLSERVER\MSSQL\Log\ERRORLOG for repeated eviction messages.
  • Cross-reference with sys.dm_os_schedulers to identify CPU pressure:
  SELECT scheduler_id, cpu_id, status, runnable_tasks_count
  FROM sys.dm_os_schedulers
  WHERE status = 'VISIBLE ONLINE';

Step 2: Increase Worker Thread and Memory Allocation

  • In SSMS, right-click the server instance → Properties → Processors tab.
  • Increase Max Worker Threads from the default (0 = auto) to a higher fixed value (e.g., 2048) if thread starvation is confirmed.
  • Navigate to Properties → Memory tab and verify Max Server Memory is not set too restrictively (leave at least 4–6 GB for the OS on Windows Server 2025).
  • Restart the SQL Server service via services.msc or:
  Restart-Service -Name 'MSSQLSERVER' -Force

Step 3: Rebuild or Reconfigure tempdb

  • Check the number and size of tempdb files:
  SELECT name, size, growth FROM tempdb.sys.database_files;
  • Ensure tempdb files are located on fast storage (NVMe/SSD) and evenly sized, e.g.:
  ALTER DATABASE tempdb MODIFY FILE (NAME = tempdev, SIZE = 2048MB, FILEGROWTH = 512MB);
  • If corruption is suspected, stop SQL Server, delete tempdb files manually, and let SQL Server recreate them on next startup.

Step 4: Apply Latest Cumulative Update

  • Check current build version:
  SELECT @@VERSION;
  • Download and install the latest SQL Server 2025 Cumulative Update (CU) from the Microsoft Update Catalog.
  • Reboot the Windows Server 2025 / Windows 11 host after installation to ensure kernel-mode drivers and SQLOS scheduler patches are applied.

Alternative or Verification Steps

  • After applying fixes, run a stress test using WAITFOR DELAY '00:00:10' in a loop across multiple sessions to confirm no eviction errors appear in the error log.
  • If the issue persists, enable Trace Flag 8047 (NUMA-aware thread allocation) at startup and monitor sys.dm_os_wait_stats for reduced SOS_SCHEDULER_YIELD waits.