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

[#116] Fix race in shm create or open #124

Closed elfenpiff closed 4 months ago

elfenpiff commented 4 months ago

Notes for Reviewer

Fixes race in posix::SharedMemory.

  1. Two processes try to create or open a shared memory
    1. Both detect that none is available
    2. Both try to create a new one - only one will succeed, the other complains: shm does not exist and I cannot create a new one.

Solution: If create fails, try to reopen it.

Removes: retrieve buffer full check from zero copy sender. The sender does not have enough information available to determine if the buffer is really insufficient. It needs to know how many samples the subscriber has currently borrowed - an information only the receiver has.

Introduce memory sync in zero copy connection open procedure. When a zero copy connection is opened and the creation is still in progress, the opener will check the init_state until it is initialized. If it is signaling that the initialization is done, it will consume the contents - without memory sync. Adding acquire / release to sync the initialized memory with the other process.

Pre-Review Checklist for the PR Author

  1. [x] Add sensible notes for the reviewer
  2. [x] PR title is short, expressive and meaningful
  3. [x] Relevant issues are linked
  4. [x] Every source code file has a copyright header with SPDX-License-Identifier: Apache-2.0 OR MIT
  5. [x] Branch follows the naming format (iox2-123-introduce-posix-ipc-example)
  6. [x] Commits messages are according to this guideline
    • [x] Commit messages have the issue ID ([#123] Add posix ipc example)
    • [x] Commit author matches Eclipse Contributor Agreement (and ECA is signed)
  7. [x] Tests follow the best practice for testing
  8. [x] Changelog updated in the unreleased section including API breaking changes
  9. [x] Assign PR to reviewer
  10. [x] All checks have passed (except task-list-completed)

Checklist for the PR Reviewer

Post-review Checklist for the PR Author

  1. [x] All open points are addressed and tracked via issues

References

Relates to #116

codecov[bot] commented 4 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (8ef4986) 77.39% compared to head (7b89058) 77.37%.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124/graphs/tree.svg?width=650&height=150&src=pr&token=FN3YFXTJCI&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx)](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx) ```diff @@ Coverage Diff @@ ## main #124 +/- ## ========================================== - Coverage 77.39% 77.37% -0.03% ========================================== Files 181 181 Lines 19615 19599 -16 ========================================== - Hits 15181 15164 -17 - Misses 4434 4435 +1 ``` | [Files](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx) | Coverage Δ | | |---|---|---| | [iceoryx2-cal/src/zero\_copy\_connection/mod.rs](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx#diff-aWNlb3J5eDItY2FsL3NyYy96ZXJvX2NvcHlfY29ubmVjdGlvbi9tb2QucnM=) | `20.68% <ø> (ø)` | | | [...al/src/zero\_copy\_connection/posix\_shared\_memory.rs](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx#diff-aWNlb3J5eDItY2FsL3NyYy96ZXJvX2NvcHlfY29ubmVjdGlvbi9wb3NpeF9zaGFyZWRfbWVtb3J5LnJz) | `89.71% <100.00%> (-0.21%)` | :arrow_down: | | [...ryx2-cal/src/zero\_copy\_connection/process\_local.rs](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx#diff-aWNlb3J5eDItY2FsL3NyYy96ZXJvX2NvcHlfY29ubmVjdGlvbi9wcm9jZXNzX2xvY2FsLnJz) | `92.30% <ø> (-0.18%)` | :arrow_down: | | [iceoryx2/src/port/publisher.rs](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx#diff-aWNlb3J5eDIvc3JjL3BvcnQvcHVibGlzaGVyLnJz) | `84.12% <100.00%> (+0.79%)` | :arrow_up: | | [iceoryx2-bb/posix/src/shared\_memory.rs](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx#diff-aWNlb3J5eDItYmIvcG9zaXgvc3JjL3NoYXJlZF9tZW1vcnkucnM=) | `81.23% <50.00%> (-0.43%)` | :arrow_down: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/eclipse-iceoryx/iceoryx2/pull/124/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=eclipse-iceoryx)