Skip to content

lifecycle_churn: add waitset/listener/cft/participants/instance scenarios (+ fixes they found) - #78

Merged
sqt merged 1 commit into
mainfrom
stress-tests-waitset-listener-cft
Sep 2, 2026
Merged

lifecycle_churn: add waitset/listener/cft/participants/instance scenarios (+ fixes they found)#78
sqt merged 1 commit into
mainfrom
stress-tests-waitset-listener-cft

Conversation

@sqt

@sqt sqt commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

The testing-tier audit's Stress tier listed five lifecycle_churn scenarios as planned but unbuilt. They cover paths with no deterministic coverage today: the DDS 1.4 §2.2.4.1.5 listener-fallback chain under teardown, WaitSet/condition-graph churn against a parked waiter, ContentFilteredTopic set_expression_parameters racing filter evaluation, many-participant fan-in/out on one domain, and the instance-lifecycle API (register_instance / write / dispose / unregister_instance / get_key_value / lookup_instance) under concurrency. Building each one surfaced a real latent bug.

Description of changes

Scenarios (stress-tests/zig/lifecycle_churn/, run.py, run_all.py, ci.yml)

  • waitset, listener, cft, participants, instance added alongside entities/reentrant. listener + cft also gated under ThreadSanitizer in CI.

Fixes the scenarios surfaced

  • listener_mask data race — a plain u32 written by set_listener and read unlocked by discovery/timer dispatch. Every runtime access in src/dcps/{writer,reader,publisher,subscriber,participant,topic}.zig is now @atomicLoad/@AtomicStore .monotonic.
  • CFT set_expression_parameters use-after-free — ContentFilteredTopicImpl gains a params_lock held across matchSample's filter_mod.eval and around the parameter swap / read.
  • Unsynchronised concurrent write() on one DataWriter — DataWriterImpl.writeRaw mutated last_sn and the get_key_value key registry with no lock. last_sn is now std.atomic.Value; the registry is guarded by a dedicated key_registry_mu. Regression: test/dcps/writer_vtable_test.zig.
  • Key-hash routing for a zero-valued / non-leading @key — a keyed writer (TypeSupport.has_key, threaded to StatefulWriter.keyed via setKeyed) now emits inline PID_KEY_HASH on every DATA/DATA_FRAG including an all-zero hash; decodeKeyHash returns ?[16]u8 and resolveKeyHash honours a present all-zero hash instead of recomputing. C-ABI zzdds_register_type_support{,_ctx} infer has_key. Regression: test/dcps/type_support_test.zig.

zidl v0.3.12 pin

  • build.zig.zon → zidl v0.3.12-zig.0.16.0 (selective CDR parse: get_key_value / get_field_from_cdr no longer use the key-only deserializer on a full sample). The instance scenario now asserts get_key_value's returned subject_id on both writer and reader sides.

@greptile-apps

greptile-apps Bot commented Sep 2, 2026

Copy link
Copy Markdown

Greptile Summary

The PR adds five lifecycle-churn stress scenarios and fixes concurrency and keyed-instance issues they exposed.

  • Makes listener masks atomic throughout the entity fallback hierarchy.
  • Synchronizes ContentFilteredTopic parameter replacement with filter evaluation.
  • Protects concurrent DataWriter sequence and key-registry state.
  • Propagates keyed-type metadata so RTPS DATA and DATA_FRAG messages preserve all-zero key hashes.
  • Pins zidl v0.3.12 and expands instance-lifecycle and sanitizer coverage.

Confidence Score: 5/5

The PR appears safe to merge; no concrete changed-code defect remained after reviewing the concurrency, lifecycle, key-routing, and build changes.

The new synchronization covers the intended mutable state, and keyed metadata and inline hashes are propagated consistently through the relevant writer and receive paths.

Important Files Changed

Filename Overview
src/dcps/writer.zig Converts writer sequence state to atomic access and serializes concurrent key-registry reads and inserts.
src/dcps/topic.zig Adds parameter locking across CFT evaluation, retrieval, and replacement to prevent concurrent use-after-free.
src/dcps/participant.zig Propagates keyed-type metadata, distinguishes absent from all-zero inline key hashes, and atomically accesses participant listener masks.
src/rtps/writer_sm.zig Emits inline key hashes consistently for keyed DATA, DATA_FRAG, replay, and retransmission paths.
src/c_abi/typesupport.zig Infers keyed-type metadata from the generated key-hash callback at both C TypeSupport registration entry points.
stress-tests/zig/lifecycle_churn/main.zig Adds wait-set, listener, CFT, participant, and instance lifecycle concurrency scenarios.
.github/workflows/ci.yml Adds listener and CFT lifecycle-churn scenarios to the ThreadSanitizer lane.
build.zig.zon Pins zidl v0.3.12 for selective CDR field parsing used by key-value extraction.

Sequence Diagram

sequenceDiagram
    participant App as Application
    participant DW as DataWriter
    participant RTPS as RTPS Writer
    participant Wire as DATA / DATA_FRAG
    participant DP as Participant Receive Path
    participant CFT as ContentFilteredTopic
    participant DR as DataReader
    App->>DW: concurrent write / lifecycle operations
    DW->>DW: atomic sequence update and locked key registry
    DW->>RTPS: sample, instance handle, key hash
    RTPS->>Wire: emit inline PID_KEY_HASH for keyed type
    Wire->>DP: receive payload and inline QoS
    DP->>DP: preserve present key hash, including all-zero
    DP->>CFT: evaluate sample
    CFT->>CFT: lock expression parameters during evaluation
    CFT-->>DR: deliver matching sample
Loading

Reviews (1): Last reviewed commit: "lifecycle_churn: add waitset/listener/cf..." | Re-trigger Greptile

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.82540% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/dcps/topic.zig 77.77% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@sqt
sqt merged commit 7af3774 into main Sep 2, 2026
39 checks passed
@sqt
sqt deleted the stress-tests-waitset-listener-cft branch September 2, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant