lowService Broker

BROKER_TASK_STOP Wait Type Explained

SQL Server BROKER_TASK_STOP wait type explained: normal Service Broker task shutdown process. Learn why this benign wait should be filtered from performance analysis.

Quick Answer

BROKER_TASK_STOP occurs when Service Broker queue task handlers shut down their worker tasks in a controlled manner. This is a benign background wait type that reflects normal Service Broker housekeeping operations and should be filtered from wait statistics analysis since it does not indicate performance problems.

Root Cause Analysis

Service Broker maintains a pool of worker tasks to process messages from activated queues. When message processing completes or queue activation thresholds change, Service Broker must gracefully shut down these worker tasks. The BROKER_TASK_STOP wait occurs during the shutdown sequence when the task handler serializes access to the task's state information to ensure the task is in a running state before termination.

The Service Broker scheduler coordinates this shutdown process through the sys.dm_broker_queue_monitors DMV mechanism. Each queue monitor tracks active tasks and their states. When a task shutdown is initiated, the system must acquire exclusive access to the task's control structure to prevent race conditions between shutdown requests and active message processing threads.

This wait type appears consistently across SQL Server versions 2016 through 2025 with no significant behavioral changes. The duration is typically measured in microseconds since it only involves checking task state flags and updating internal counters. Even databases with no active Service Broker applications may show minimal BROKER_TASK_STOP waits due to system queue maintenance.

AutoDBA checks wait statistics filtering, Service Broker monitoring, and background process analysis across your entire SQL Server instance in 60 seconds. Download the free diagnostic script and see what else needs attention.

Diagnostic Queries

-- Check BROKER_TASK_STOP wait statistics
SELECT 
    wait_type,
    waiting_tasks_count,
    wait_time_ms,
    max_wait_time_ms,
    signal_wait_time_ms,
    wait_time_ms / NULLIF(waiting_tasks_count, 0) AS avg_wait_ms
FROM sys.dm_os_wait_stats 
WHERE wait_type = 'BROKER_TASK_STOP';

-- Query to show filtered wait stats excluding benign waits
SELECT 
    wait_type,
    wait_time_ms,
    waiting_tasks_count,
    CAST(100.0 * wait_time_ms / SUM(wait_time_ms) OVER() AS DECIMAL(5,2)) AS pct_of_waits
FROM sys.dm_os_wait_stats
WHERE wait_type NOT IN (
    'BROKER_EVENTHANDLER', 'BROKER_RECEIVE_WAITFOR', 'BROKER_TASK_STOP',
    'BROKER_TO_FLUSH', 'BROKER_TRANSMITTER', 'CHECKPOINT_QUEUE',
    'CHKPT', 'CLR_AUTO_EVENT', 'CLR_MANUAL_EVENT', 'CLR_SEMAPHORE',
    'DBMIRROR_DBM_EVENT', 'DBMIRROR_EVENTS_QUEUE', 'DBMIRROR_WORKER_QUEUE',
    'DBMIRRORING_CMD', 'DIRTY_PAGE_POLL', 'DISPATCHER_QUEUE_SEMAPHORE',
    'EXECSYNC', 'FSAGENT', 'FT_IFTS_SCHEDULER_IDLE_WAIT', 'FT_IFTSHC_MUTEX',
    'HADR_CLUSAPI_CALL', 'HADR_FILESTREAM_IOMGR_IOCOMPLETION', 'HADR_LOGCAPTURE_WAIT',
    'HADR_NOTIFICATION_DEQUEUE', 'HADR_TIMER_TASK', 'HADR_WORK_QUEUE',
    'KSOURCE_WAKEUP', 'LAZYWRITER_SLEEP', 'LOGMGR_QUEUE',
    'MEMORY_ALLOCATION_EXT', 'ONDEMAND_TASK_QUEUE',
    'PARALLEL_REDO_DRAINER_WORKER', 'PARALLEL_REDO_LOG_CACHE', 'PARALLEL_REDO_TRAN_LIST',
    'PARALLEL_REDO_WORKER_SYNC', 'PARALLEL_REDO_WORKER_WAIT_WORK',
    'PREEMPTIVE_XE_GETTARGETSTATE', 'PWAIT_ALL_COMPONENTS_INITIALIZED',
    'PWAIT_DIRECTLOGCONSUMER_GETNEXT', 'QDS_PERSIST_TASK_MAIN_LOOP_SLEEP',
    'QDS_ASYNC_QUEUE', 'QDS_CLEANUP_STALE_QUERIES_TASK_MAIN_LOOP_SLEEP',
    'REQUEST_FOR_DEADLOCK_SEARCH', 'RESOURCE_QUEUE', 'SERVER_IDLE_CHECK',
    'SLEEP_BPOOL_FLUSH', 'SLEEP_DBSTARTUP', 'SLEEP_DCOMSTARTUP',
    'SLEEP_MASTERDBREADY', 'SLEEP_MASTERMDREADY', 'SLEEP_MASTERUPGRADED',
    'SLEEP_MSDBSTARTUP', 'SLEEP_SYSTEMTASK', 'SLEEP_TASK',
    'SLEEP_TEMPDBSTARTUP', 'SNI_HTTP_ACCEPT', 'SP_SERVER_DIAGNOSTICS_SLEEP',
    'SQLTRACE_BUFFER_FLUSH', 'SQLTRACE_INCREMENTAL_FLUSH_SLEEP',
    'SQLTRACE_WAIT_ENTRIES', 'WAIT_FOR_RESULTS', 'WAITFOR',
    'WAITFOR_TASKSHUTDOWN', 'WAIT_XTP_RECOVERY',
    'WAIT_XTP_HOST_WAIT', 'WAIT_XTP_OFFLINE_CKPT_NEW_LOG', 'WAIT_XTP_CKPT_CLOSE',
    'XE_DISPATCHER_JOIN', 'XE_DISPATCHER_WAIT', 'XE_TIMER_EVENT')
AND wait_time_ms > 0
ORDER BY wait_time_ms DESC;

Prevention

No prevention is required since BROKER_TASK_STOP represents normal Service Broker operations. Attempting to eliminate this wait would require disabling Service Broker entirely, which is unnecessary and potentially disruptive to system databases that rely on Service Broker for internal messaging. Focus performance tuning efforts on actionable wait types that indicate resource contention or inefficient query patterns.

Monitoring tools like AutoDBA automatically filter benign waits including BROKER_TASK_STOP, allowing DBAs to concentrate on waits that actually impact user experience and system performance.

Need hands-on help?

Dealing with persistent broker_task_stop issues across your environment? Samix Technology provides hands-on SQL Server performance consulting with 15+ years of production DBA experience.

Related Pages