﻿# Completion notifications can arrive for an empty RDMA CQ

Handle one-shot CQ rearming, polling and event acknowledgement without assuming that every completion-channel event still has a queue entry.

Author: Retrivium team
Updated: 2026-11-06
Canonical URL: https://retrivium.ai/journal/rdma-cq-notification-rearm-race/
Language: en

## The wake-up has no remaining entry

An event-driven RDMA worker wakes on its completion channel, polls the corresponding CQ and finds it empty. Declaring corruption or a lost completion at that point can be wrong. Notification delivery and queue polling are different mechanisms with different lifetimes. A completion may already have been consumed even though a corresponding channel event remains pending. The handler needs a documented race-safe protocol rather than a one-event-equals-one-entry assumption.

## Notification requests are one shot

The [ibv_req_notify_cq reference](https://man7.org/linux/man-pages/man3/ibv_req_notify_cq.3.html) states that a notification request is one shot. Another event requires another request. It also distinguishes solicited-only requests from requests for any new completion: successful send completions are not solicited. Consequently, an application can appear hung if it selects a filter inconsistent with its work or fails to rearm. Polling a CQ does not by itself express a new request for a future channel event.

## The documented extra-event race

The [ibv_get_cq_event example](https://man7.org/linux/man-pages/man3/ibv_get_cq_event.3.html) requests the next notification before draining the CQ. A new completion can arrive between rearming and draining, generate a channel event, and then be consumed during that drain. When the event is retrieved later, no corresponding entry remains. The documentation explicitly permits this case. The empty poll therefore does not independently prove a transport failure, and inserting a fatal assertion would turn a valid race into an application outage.

## Preserve the handling sequence

Build the event loop around initial notification setup, retrieval of the actual CQ identity, acknowledgement accounting, renewed notification and complete polling of available entries. Follow the provider's documented sequence and inspect return values at every boundary. If multiple queues share a channel, use the returned CQ rather than assuming the event concerns the worker's preferred queue. A negative polling result is an API failure; a successful poll returning no entries is a different condition requiring different handling.

## Account for events separately

Every successfully retrieved completion event must be acknowledged. The reference explains that CQ destruction waits for outstanding acknowledgements, so ignoring extra events can later turn shutdown into an unexplained wait. Batching acknowledgements is possible with correct per-CQ counts; work completions are not the unit of this accounting. In an isolated test, arrange arrivals around rearming and draining, then verify useful completion progress, tolerance of empty wakes and balanced event acknowledgements through teardown.

## Acceptance without a false one-to-one rule

The accepted loop neither loses future notification coverage nor invents a completion when an event has no remaining entry. It preserves error paths, queue identity and a bounded shutdown policy appropriate to the application. The [existing completion guide](/journal/guide-net-rdma-completion/) explains work-completion errors and buffer consequences, while [memory registration lifetime](/journal/guide-net-rdma-memory-registration/) addresses resources those operations reference. This procedure establishes notification handling, not remote application commit or universal transport ordering. Keep event counts, polled entries and accepted application operations as distinct evidence streams.
