Proposal: Expose `is_data_valid` API for Loaned/Zero-Copy Messages
I maintainer di solito rispondono entro 1 giorno
@kamal2730 ci sta già lavorando.
Dal 4/4/2026.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Da chiarire
- Stato di attività
- Tranquilla
- Stack tecnologico
- cpp
- Ambito
- api, backend-api-design
Direzione di ricerca
Inizia leggendo le aree delle API rclcpp MessageInfo e Subscription, quindi confronta il pattern dell’interfaccia nativa di rmw_fastrtps_cpp menzionato nella proposta. Determina il confine previsto tra i controlli specifici del vendor, quelli generici di rmw e quelli di rclcpp rivolti all’utente; il lavoro è completato quando il comportamento dell’API è definito per i casi copiati, loaned validi, loaned invalidati e middleware non supportati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
introduce an API at the rclcpp level that allows users to check whether loaned message memory is still valid (i.e., has not been overwritten by the middleware). this addresses a long-standing safety gap when using loaned messages and zero-copy transport with middleware implementations that reuse shared memory (e.g., Fast-DDS with data-sharing).
Motivation
when using loaned messages, especially with zero-copy pipelines over shared memory, the middleware may overwrite previously loaned memory under certain conditions:
- the publisher and subscriber share a history cache in shared memory, so the publisher can cause changes in the subscriber's loaned memory even while the subscriber still holds a reference.
- with PREALLOCATED_WITH_REALLOC memory policy, shared memory still in use may be reissued to new incoming samples.
- the subscriber currently has no way to detect that its loaned data has been silently invalidated.
while loans were disabled in the executor as a short-term fix, the underlying problem remains for users who explicitly opt into loaned messages or zero-copy transports. currently, Fast-DDS provides an internal is_valid mechanism for data-sharing samples, but this is not exposed through any ROS 2 API layer.
Design / Implementation Considerations
the proposal approach is to add RMW Native Interface Pattern.
following the established pattern used by rmw_fastrtps_cpp to expose vendor-specific functionality (e.g., get_participant, get_subscriber, get_publisher), we propose a similar approach to expose data validity checks.
- rmw_fastrtps (vendor-specific): rmw implementation that supports loaned messages with shared memory can expose a native validity check. middleware implementations that do not have this concern (e.g., Cyclone DDS, which allocates fresh memory) can either not implement this or always return true.
- rmw interface (optional, generic): a generic function could be added to the rmw interface to allow middleware-agnostic checking. implementations that don't support or need this would return RMW_RET_UNSUPPORTED or set is_valid = true.
- rclcpp (user-facing): expose the check through MessageInfo or the Subscription object so that users can query validity without reaching down to vendor-specific APIs like
is_loaned_message_valid.
| Scenario | is_data_valid returns |
|---|---|
| Message was not loaned (normal copy) | true (always safe) |
| Loaned message, memory still intact | true |
| Loaned message, memory overwritten by publisher/pool | false |
| Middleware does not support validity checking | true (safe default) |
Additional Information
several fixes have been applied or proposed (disabling loans, fixing the memory pool, returning loans via shared_ptr destructor).
- zero-copy over shared memory inherently involves memory that the publisher can modify. this is by design in the DDS data-sharing model.
- even with fixes to the executor and memory pool, advanced users opting into zero-copy need a mechanism to detect invalidation.
- defense-in-depth: even if the middleware "should" not overwrite in-use memory, having a user-facing validity check provides a safety net.
in the original discussion, this check is inherently racy for true zero-copy over shared memory, memory could become invalid during a read. the is_data_valid API is therefore best suited as:
- a post-read sanity check (read data, then verify it wasn't corrupted)
- a debugging/diagnostic tool to identify when memory reuse issues occur
- a guard before processing in non-real-time paths
it is not a substitute for proper loan lifetime management (returning loans via shared_ptr destructor, etc.).
- Lingua principale
- C++
- Stelle
- 814
- Fork
- 572
- Merge medio
- 5g 3h
- PR unite (30g)
- 17
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di ros2/rclcpp
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
I maintainer di solito rispondono entro 1 giorno
-
Copy constructor exception leaks intra-process message allocationForse già presa @TinyGeek l’ha presa 2 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
[Jazzy] action server registers clock jump callbacks without the clock mutex (heap corruption)Forse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 44/100
I maintainer di solito rispondono entro 1 giorno
-
EventsCBGExecutor segfaults when a timer is removed while its callback is runningForse già presa @spurnvoj l’ha presa 7 giorni fa. Apertabug
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
-
EventsCBGExecutor keeps queued events of removed nodes, component container segfaults on shutdownForse già presa @spurnvoj l’ha presa 7 giorni fa. Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 18/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
I maintainer di solito rispondono entro 4 giorni
-
nth_root does not restore the rounding mode and can return an upper bound below the true rootAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
scanaislop/aislop#482 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
EchoTools/nevr-runtime#547 ·
I maintainer di solito rispondono entro 1 giorno
-
1 type: problem 2 scope: firmware 3 good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
SpaceTeam/STS1_COBC_SW#511 ·