-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iox-#1821 improve error message when creating read-only segment #1822
iox-#1821 improve error message when creating read-only segment #1822
Conversation
@elfenpiff I finally got around to addressing the confusing error message when combining READ_ONLY with CREATE in shared-memory segments. In our last discussion you suggested that we shouldn't handle this with an error; instead, you proposed the following API that makes the error impossible: auto shmCreated = SharedMemoryObjectBuilder()
// all the usual settings without accessMode, is always created with ReadWrite
.create();
auto shmOpen = SharedMemoryObjectBuilder()
// now it is also definitely clear that we open the shm and the other owns it
.open(AccessMode::READ); Thinking more about it, I'm a bit concerned that this re-defines the meaning of The second thing that feels wrong is that the open/create distinction overlaps Do you see a good way to avoid this? Or should I just add a new return code, say, |
Codecov Report
@@ Coverage Diff @@
## master #1822 +/- ##
=======================================
Coverage 75.43% 75.43%
=======================================
Files 377 377
Lines 14625 14627 +2
Branches 2086 2087 +1
=======================================
+ Hits 11032 11034 +2
- Misses 2960 2961 +1
+ Partials 633 632 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
iceoryx_hoofs/test/moduletests/test_posix_shared_memory_object.cpp
Outdated
Show resolved
Hide resolved
iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp
Outdated
Show resolved
Hide resolved
@@ -142,7 +142,7 @@ cxx::expected<SharedMemory, SharedMemoryError> SharedMemoryBuilder::create() noe | |||
<< "\". This may be a SharedMemory leak." << std::endl; | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a good solution would be to add a check right before ftrunctate
in line 122.
If here the shared memory hasOwnership
and the m_accessMode == AccessMode::READ_ONLY
it should fail.
For this you could introduce a new SharedMemoryError
enum value and return it here in combination with an error message. This could then also be verified in the unit test and wouldn't fail in windows.
Or you could do a check right in the beginning of the create()
method to verify that OpenMode::**CREATE**
is not combined with AccessMode::READ_ONLY
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elfenpiff I implemented something similar to your suggestion. Checking before the truncate
would work, but it could potentially hide errors. I believe we want to complain about READ_ONLY + OPEN_OR_CREATE, even if the file happens to already exist.
So I moved the check up, before the open-if-exist attempt. Since hasOwnership
now has to be in scope during the open-check, I also used the opportunity to simplify the code there (the non-owning success path can now follow the same code path as the owning success path, with hasOwnership
distinguishing between the two).
Pipeline seems to run through, the invalid links are not caused by this MR.
/cc @mossmaurice
3538f85
to
8e00b8d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Sorry for the long delay in review.
@tobiasblass ... oh, and it seems you have to rebase |
Signed-off-by: Tobias Stark <[email protected]>
ee3d5a9
8e00b8d
to
ee3d5a9
Compare
iceoryx_hoofs/source/posix_wrapper/shared_memory_object/shared_memory.cpp
Outdated
Show resolved
Hide resolved
…Builder Signed-off-by: Tobias Stark <[email protected]>
ee3d5a9
to
d4396a5
Compare
@elfenpiff I've rebased to latest master. Can you re-approve for the second approval? |
@tobiasblass took quite some time but finally it is merged. For the next PR we have to improve our review time :) |
Pre-Review Checklist for the PR Author
iox-123-this-is-a-branch
)iox-#123 commit text
)task-list-completed
)iceoryx_hoofs
are added to./clang-tidy-diff-scans.txt
Notes for Reviewer
Checklist for the PR Reviewer
iceoryx_hoofs
have been added to./clang-tidy-diff-scans.txt
Post-review Checklist for the PR Author
References