eclipse-iceoryx / iceoryx2

Eclipse iceoryx2™ - true zero-copy inter-process-communication in pure Rust
https://iceoryx.io
Apache License 2.0
449 stars 22 forks source link

Publisher retrieves invalid sample when subscriber is connected #131

Closed elfenpiff closed 3 months ago

elfenpiff commented 4 months ago

Required information

Operating system: Linux 6.7.3-arch1-2

Rust version: rustc 1.76.0 (07dca489a 2024-02-04)

Cargo version: rustc 1.76.0 (07dca489a 2024-02-04)

iceoryx2 version: main branch

Fix: On publisher side, for the offset calculations when using a pool allocator, we had the implicit requirement that the offsets start at zero and are a multiple of the bucket size. Introducing for the normal allocators a method that returns the smallest start point of the payload and for the shm allocators a method that returns the relative payload starting offset and use this in the SharedMemory concept as the starting point fixed the problem.

Observed result or behaviour: When a new subscriber connects, the publisher suddenly retrieves an invalid sample.

Expected result or behaviour: No invalid samples are retrieved

Conditions where it occurred / Performed steps:

       61 [T] SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 85, data: "iox2_1527439745112502164476023069140769_155754
              6446867922612761728747364181.connection" } }, size: 190, base_address: 0x794f63baa000, has_ownership: true, file_descriptor: Fil
              eDescriptor { value: 7, is_owned: true }, memory_lock: None }
              | create
       62 [D] PoolAllocator { buckets: UniqueIndexSet { data_ptr: RelocatablePointer { distance: 112, _phantom: PhantomData<core::cell::Unsafe
              Cell<u32>> }, capacity: 36, borrowed_indices: 21, head: 90359339105, is_memory_initialized: true }, bucket_size: 128360, bucket_
              alignment: 8, start: 133381875593496, size: 4620967, is_memory_initialized: true }
              | Tried to release memory (133381875593494) which does not belong to this allocator.
       63 [D] PoolAllocator { allocator: PoolAllocator { buckets: UniqueIndexSet { data_ptr: RelocatablePointer { distance: 112, _phantom: Pha
              ntomData<core::cell::UnsafeCell<u32>> }, capacity: 36, borrowed_indices: 21, head: 90359339105, is_memory_initialized: true }, b
              ucket_size: 128360, bucket_alignment: 8, start: 133381875593496, size: 4620967, is_memory_initialized: true }, base_address: 133
              381875593494, max_supported_alignment_by_memory: 4096 }
              | Failed to release shared memory chunk
       64 [D] Memory { shared_memory: SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 60, data: "iox2_19279_15274397451
              12502164476023069140769.publisher_data" } }, size: 4621245, base_address: 0x794f63507000, has_ownership: true, file_descriptor: 
              FileDescriptor { value: 5, is_owned: true }, memory_lock: None }, name: FileName { value: FixedSizeByteString<255> { len: 40, da
              ta: "19279_1527439745112502164476023069140769" } }, allocator: 0x794f63507000 }
              | Failed to deallocate shared memory chunk due to an internal allocator failure.
       65 [F] Publisher { port_id: UniquePublisherId(UniqueSystemId { value: 1527439745112502164476023069140769 }), sample_reference_counter: 
              [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], data_segment: Memo
              ry { shared_memory: SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 60, data: "iox2_19279_152743974511250
              2164476023069140769.publisher_data" } }, size: 4621245, base_address: 0x794f63507000, has_ownership: true, file_descriptor: File
              Descriptor { value: 5, is_owned: true }, memory_lock: None }, name: FileName { value: FixedSizeByteString<255> { len: 40, data: 
              "19279_1527439745112502164476023069140769" } }, allocator: 0x794f63507000 }, config: LocalPublisherConfig { max_loaned_samples: 
              2, unable_to_deliver_strategy: Block }, dynamic_storage: Storage { shm: SharedMemory { name: FileName { value: FixedSizeByteStri
              ng<255> { len: 53, data: "iox2_b61bd15e8c3ea16146985e960906a8e125156a73.dynamic" } }, size: 422, base_address: 0x794f63bac000, h
              as_ownership: false, file_descriptor: FileDescriptor { value: 4, is_owned: true }, memory_lock: None }, name: FileName { value: 
              FixedSizeByteString<255> { len: 40, data: "b61bd15e8c3ea16146985e960906a8e125156a73" } }, _phantom_data: PhantomData<iceoryx2::s
              ervice::dynamic_config::DynamicConfig> }, subscriber_connections: SubscriberConnections { connections: [UnsafeCell { .. }, Unsaf
              eCell { .. }, UnsafeCell { .. }, UnsafeCell { .. }, UnsafeCell { .. }, UnsafeCell { .. }, UnsafeCell { .. }, UnsafeCell { .. }],
               port_id: UniquePublisherId(UniqueSystemId { value: 1527439745112502164476023069140769 }), config: Config { global: Global { roo
              t_path_unix: "/tmp/iceoryx2/", root_path_windows: "c:\\Temp\\iceoryx2\\", prefix: "iox2_", service: Service { directory: "servic
              es", publisher_data_segment_suffix: ".publisher_data", static_config_storage_suffix: ".service", dynamic_config_storage_suffix: 
              ".dynamic", creation_timeout: 500ms, connection_suffix: ".connection" } }, defaults: Defaults { publish_subscribe: PublishSubscr
              ibe { max_subscribers: 8, max_publishers: 2, subscriber_max_buffer_size: 2, subscriber_max_borrowed_samples: 2, publisher_max_lo
              aned_samples: 2, publisher_history_size: 1, enable_safe_overflow: true, unable_to_deliver_strategy: Block }, event: Event { max_
              listeners: 2, max_notifiers: 16 } } }, static_config: StaticConfig { max_subscribers: 8, max_publishers: 2, history_size: 1, sub
              scriber_max_buffer_size: 2, subscriber_max_borrowed_samples: 2, enable_safe_overflow: true, type_name: "publish_subscribe_publis
              her::BigMessage" } }, subscriber_list_state: UnsafeCell { .. }, history: Some(UnsafeCell { .. }), service: Service { state: Serv
              iceState { static_config: StaticConfig { uuid: "b61bd15e8c3ea16146985e960906a8e125156a73", service_name: ServiceName { value: Fi
              xedSizeByteString<255> { len: 19, data: "My/Funk/ServiceName" } }, messaging_pattern: PublishSubscribe(StaticConfig { max_subscr
              ibers: 8, max_publishers: 2, history_size: 1, subscriber_max_buffer_size: 2, subscriber_max_borrowed_samples: 2, enable_safe_ove
              rflow: true, type_name: "publish_subscribe_publisher::BigMessage" }) }, global_config: Config { global: Global { root_path_unix:
               "/tmp/iceoryx2/", root_path_windows: "c:\\Temp\\iceoryx2\\", prefix: "iox2_", service: Service { directory: "services", publish
              er_data_segment_suffix: ".publisher_data", static_config_storage_suffix: ".service", dynamic_config_storage_suffix: ".dynamic", 
              creation_timeout: 500ms, connection_suffix: ".connection" } }, defaults: Defaults { publish_subscribe: PublishSubscribe { max_su
              bscribers: 8, max_publishers: 2, subscriber_max_buffer_size: 2, subscriber_max_borrowed_samples: 2, publisher_max_loaned_samples
              : 2, publisher_history_size: 1, enable_safe_overflow: true, unable_to_deliver_strategy: Block }, event: Event { max_listeners: 2
              , max_notifiers: 16 } } }, dynamic_storage: Storage { shm: SharedMemory { name: FileName { value: FixedSizeByteString<255> { len
              : 53, data: "iox2_b61bd15e8c3ea16146985e960906a8e125156a73.dynamic" } }, size: 422, base_address: 0x794f63bac000, has_ownership:
               false, file_descriptor: FileDescriptor { value: 4, is_owned: true }, memory_lock: None }, name: FileName { value: FixedSizeByte
              String<255> { len: 40, data: "b61bd15e8c3ea16146985e960906a8e125156a73" } }, _phantom_data: PhantomData<iceoryx2::service::dynam
              ic_config::DynamicConfig> }, static_storage: Storage { name: FileName { value: FixedSizeByteString<255> { len: 40, data: "b61bd1
              5e8c3ea16146985e960906a8e125156a73" } }, config: Configuration { path: Path { value: FixedSizeByteString<4096> { len: 22, data: 
              "/tmp/iceoryx2/services" } }, suffix: FileName { value: FixedSizeByteString<255> { len: 8, data: ".service" } }, prefix: FileNam
              e { value: FixedSizeByteString<255> { len: 5, data: "iox2_" } } }, has_ownership: false, file: File { path: Some(FilePath { valu
              e: FixedSizeByteString<4096> { len: 76, data: "/tmp/iceoryx2/services/iox2_b61bd15e8c3ea16146985e960906a8e125156a73.service" } }
              ), file_descriptor: FileDescriptor { value: 3, is_owned: true }, has_ownership: false }, len: 352 } } }, degration_callback: Non
              e, loan_counter: 1, dynamic_publisher_handle: ContainerHandle { index: 0, container_id: 1 }, _phantom_message_type: PhantomData<
              publish_subscribe_publisher::BigMessage> }
              | Internal logic error. The sample should always contain a valid memory chunk from the provided allocator.