mediumService Broker

BROKER_CONNECTION_RECEIVE_TASK Wait Type Explained

Fix BROKER_CONNECTION_RECEIVE_TASK waits in SQL Server Service Broker. Diagnostic queries, configuration scripts, and prevention strategies for connection endpoint serialization issues.

Quick Answer

BROKER_CONNECTION_RECEIVE_TASK occurs when Service Broker connections are serialized while waiting to receive messages on connection endpoints. This wait type typically indicates either high Service Broker message volume overwhelming receive capacity or network latency issues between Service Broker endpoints. Medium severity because it can impact Service Broker application performance but doesn't affect other SQL Server operations.

Root Cause Analysis

Service Broker uses connection endpoints to manage message transmission between services. The BROKER_CONNECTION_RECEIVE_TASK wait occurs when multiple tasks attempt to receive messages on the same connection endpoint simultaneously. SQL Server serializes access to ensure message ordering and prevent corruption.

The wait manifests when the Service Broker receive task manager cannot immediately access the connection endpoint's receive buffer. This happens because another task is already processing messages on that endpoint, or the network stack is still assembling incoming message fragments. The wait duration directly correlates with message processing time and network round-trip latency.

In SQL Server 2016 and later, Microsoft improved Service Broker connection pooling and message batching, reducing these waits under normal load. However, the fundamental serialization behavior remains unchanged. SQL Server 2019 introduced better diagnostic information in sys.dm_broker_connections, making troubleshooting more precise.

The wait becomes problematic when message receive rates exceed the endpoint's processing capacity, creating a backlog. This often occurs with small, frequent messages that don't benefit from batching optimizations, or when network latency increases message assembly time.

Connection endpoint serialization also protects against message corruption during high-concurrency scenarios. Without this serialization, message fragments could interleave, causing data integrity issues that would be nearly impossible to diagnose.

AutoDBA checks Service Broker endpoint configuration, queue reader settings, and message forwarding optimization across your entire SQL Server instance in 60 seconds. Download the free diagnostic script and see what else needs attention.

Diagnostic Queries

-- Check Service Broker connection status
SELECT 
    connection_id,
    state_desc,
    connect_time,
    login_state_desc,
    peer_certificate_id,
    receives_posted,
    sends_posted
FROM sys.dm_broker_connections
WHERE state_desc != 'DISCONNECTED'
ORDER BY receives_posted DESC;
-- Identify Service Broker queues with high message volumes
SELECT 
    q.name,
    q.is_activation_enabled,
    q.activation_procedure,
    q.max_readers,
    qs.last_activated_time,
    qs.last_empty_rowset_time,
    qs.state
FROM sys.service_queues q
JOIN sys.dm_broker_queue_monitors qs ON q.object_id = qs.queue_id
ORDER BY qs.last_activated_time DESC;
-- Check for Service Broker endpoint configuration issues
SELECT 
    e.name,
    e.type_desc,
    e.state_desc,
    e.is_admin_endpoint,
    sb.connection_auth_desc,
    sb.encryption_algorithm_desc,
    sb.message_forwarding_size
FROM sys.endpoints e
JOIN sys.service_broker_endpoints sb ON e.endpoint_id = sb.endpoint_id
WHERE e.type = 4; -- SERVICE_BROKER type
-- Monitor current BROKER_CONNECTION_RECEIVE_TASK waits
SELECT 
    session_id,
    wait_type,
    wait_time_ms,
    blocking_session_id,
    wait_resource,
    resource_description
FROM sys.dm_exec_requests
WHERE wait_type = 'BROKER_CONNECTION_RECEIVE_TASK'
AND session_id > 50;
-- Historical wait statistics for Service Broker waits
SELECT 
    wait_type,
    waiting_tasks_count,
    wait_time_ms,
    max_wait_time_ms,
    signal_wait_time_ms,
    wait_time_ms / waiting_tasks_count AS avg_wait_time_ms
FROM sys.dm_os_wait_stats
WHERE wait_type LIKE 'BROKER%'
AND waiting_tasks_count > 0
ORDER BY wait_time_ms DESC;

Fix Scripts

Increase Service Broker Queue Readers This script increases the maximum concurrent readers for high-volume Service Broker queues to reduce connection endpoint contention.

-- Increase max readers for high-volume queues
-- TEST IN DEVELOPMENT FIRST
DECLARE @queue_name NVARCHAR(128) = 'YourHighVolumeQueue';
DECLARE @sql NVARCHAR(MAX);

SET @sql = N'ALTER QUEUE ' + QUOTENAME(@queue_name) + N' WITH ACTIVATION (MAX_QUEUE_READERS = 5);';
EXEC sp_executesql @sql;

-- Verify the change
SELECT name, max_readers FROM sys.service_queues WHERE name = @queue_name;

Configure Service Broker Message Forwarding Size Adjusts message forwarding buffer size to handle larger message batches and reduce connection endpoint serialization.

-- Increase message forwarding size for Service Broker endpoints
-- This reduces the number of small message batches
DECLARE @endpoint_name NVARCHAR(128) = 'YourServiceBrokerEndpoint';

ALTER ENDPOINT [YourServiceBrokerEndpoint]
FOR SERVICE_BROKER (
    MESSAGE_FORWARDING_SIZE = 1024  -- Default is 128
);

-- Verify endpoint configuration
SELECT 
    e.name,
    sb.message_forwarding_size
FROM sys.endpoints e
JOIN sys.service_broker_endpoints sb ON e.endpoint_id = sb.endpoint_id
WHERE e.name = @endpoint_name;

Enable Service Broker Queue Activation Configures automatic queue processing to prevent message accumulation that leads to connection endpoint waits.

-- Configure queue activation to process messages automatically
-- Replace with your actual stored procedure and max readers count
ALTER QUEUE [YourServiceBrokerQueue] WITH 
    ACTIVATION (
        STATUS = ON,
        PROCEDURE_NAME = [dbo].[YourMessageProcessingProcedure],
        MAX_QUEUE_READERS = 3,
        EXECUTE AS OWNER
    );

-- Monitor activation effectiveness
SELECT 
    q.name,
    qm.last_activated_time,
    qm.state,
    qm.tasks_waiting
FROM sys.service_queues q
JOIN sys.dm_broker_queue_monitors qm ON q.object_id = qm.queue_id
WHERE q.name = 'YourServiceBrokerQueue';

Optimize Network Settings for Service Broker Configures TCP settings to reduce network-related message assembly delays.

-- Check current network configuration for Service Broker endpoints
SELECT 
    e.name,
    e.protocol_desc,
    t.port,
    t.is_dynamic_port,
    t.ip_address
FROM sys.endpoints e
LEFT JOIN sys.tcp_endpoints t ON e.endpoint_id = t.endpoint_id
WHERE e.type_desc = 'SERVICE_BROKER';

-- Note: Network buffer optimizations require OS-level changes
-- Consider increasing TCP receive window size at the OS level
-- This script only shows current configuration

AutoDBA generates fix scripts like these automatically, with impact estimates and rollback SQL included.

Prevention

Configure Service Broker queue activation with appropriate MAX_QUEUE_READERS values based on message volume patterns. Monitor message queue depths daily and adjust reader counts before queues accumulate excessive backlogs.

Set MESSAGE_FORWARDING_SIZE to 512 or 1024 bytes for endpoints handling frequent small messages. This reduces the number of individual receive operations per connection endpoint, decreasing serialization contention.

Implement connection pooling at the application layer when possible. Multiple applications connecting to the same Service Broker service should reuse connections rather than creating new endpoints for each operation.

Monitor network latency between Service Broker endpoints using ping and traceroute. Network delays directly impact message assembly time, increasing the duration of BROKER_CONNECTION_RECEIVE_TASK waits.

Use message batching in Service Broker applications. Send multiple related messages in a single conversation rather than individual messages, reducing the total number of receive operations required.

Establish baseline monitoring for sys.dm_broker_queue_monitors and alert when messages_in_queue exceeds normal thresholds. Early detection prevents queue backlogs that exacerbate connection endpoint contention.

Consider partitioning high-volume Service Broker services across multiple endpoints and physical networks when message volumes consistently create connection bottlenecks that cannot be resolved through configuration changes alone.

Need hands-on help?

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

Related Pages