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

Stop/Start subscriber leads to OutOfMemory on publisher side #130

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: The problem had two causes:

The UsedChunkList from iceoryx1 was ported and whenever a connection is terminated all samples from the UsedChunkList will be recycled.

Observed result or behaviour: When a subscriber is stopped and reconnected, it can lead to a OutOfMemory error on the publisher side.

Expected result or behaviour: No out of memory.

Conditions where it occurred / Performed steps:

       96 [D] SharedMemoryBuilder { name: FileName { value: FixedSizeByteString<255> { len: 85, data: "iox2_1439258800234125956732939963044004
              _1512227937909763411657611488120570.connection" } }, size: 190, is_memory_locked: false, has_ownership: true, permission: OWNER_
              READ | OWNER_WRITE | OWNER_EXEC | OWNER_ALL, creation_mode: Some(OpenOrCreate), zero_memory: true, access_mode: ReadWrite, enfor
              ce_base_address: None }
              | Unable to create shared memory since it already exists.
       97 [T] SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 85, data: "iox2_1439258800234125956732939963044004_151222
              7937909763411657611488120570.connection" } }, size: 190, base_address: 0x79024f6b1000, has_ownership: true, file_descriptor: Fil
              eDescriptor { value: 6, is_owned: true }, memory_lock: None }
              | create
       98 [D] PoolAllocator { buckets: UniqueIndexSet { data_ptr: RelocatablePointer { distance: 112, _phantom: PhantomData<core::cell::Unsafe
              Cell<u32>> }, capacity: 36, borrowed_indices: 36, head: 157183357176, is_memory_initialized: true }, bucket_size: 128360, bucket
              _alignment: 8, start: 133050822349080, size: 4620967, is_memory_initialized: true }
              | No more buckets available to allocate 128360 bytes with an alignment of 8.
       99 [D] PoolAllocator { allocator: PoolAllocator { buckets: UniqueIndexSet { data_ptr: RelocatablePointer { distance: 112, _phantom: Pha
              ntomData<core::cell::UnsafeCell<u32>> }, capacity: 36, borrowed_indices: 36, head: 157183357176, is_memory_initialized: true }, 
              bucket_size: 128360, bucket_alignment: 8, start: 133050822349080, size: 4620967, is_memory_initialized: true }, base_address: 13
              3050822349078, max_supported_alignment_by_memory: 4096 }
              | Unable to allocate memory.
      100 [D] Memory { shared_memory: SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 60, data: "iox2_18166_14392588002
              34125956732939963044004.publisher_data" } }, size: 4621245, base_address: 0x79024f00d000, has_ownership: true, file_descriptor: 
              FileDescriptor { value: 5, is_owned: true }, memory_lock: None }, name: FileName { value: FixedSizeByteString<255> { len: 40, da
              ta: "18166_1439258800234125956732939963044004" } }, allocator: 0x79024f00d000 }
              | Failed to allocate shared memory due to an internal allocator failure.
      101 [D] Publisher { port_id: UniquePublisherId(UniqueSystemId { value: 1439258800234125956732939963044004 }), sample_reference_counter: 
              [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1], data_segment: Memo
              ry { shared_memory: SharedMemory { name: FileName { value: FixedSizeByteString<255> { len: 60, data: "iox2_18166_143925880023412
              5956732939963044004.publisher_data" } }, size: 4621245, base_address: 0x79024f00d000, has_ownership: true, file_descriptor: File
              Descriptor { value: 5, is_owned: true }, memory_lock: None }, name: FileName { value: FixedSizeByteString<255> { len: 40, data: 
              "18166_1439258800234125956732939963044004" } }, allocator: 0x79024f00d000 }, 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: 0x79024f6b2000, 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: 1439258800234125956732939963044004 }), 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: 0x79024f6b2000, 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: 0, dynamic_publisher_handle: ContainerHandle { index: 0, container_id: 1 }, _phantom_message_type: PhantomData<
              publish_subscribe_publisher::BigMessage> }
              | Unable to loan Sample since the underlying shared memory is out of memory.