Make function std::ping::ping concurrency safe#7
Closed
michael-hartmann wants to merge 1 commit into
Closed
Conversation
The function `ping` so far did not check the ident received. As a consequence the function `ping` might returned wrong results when used simultaneously from different threads, see aisk#6 for more details. This commit fixes the issue by checking the ident of the reply and comparing it with the expected ident. Changes: * Changed type of `timeout` from `Option<Duration>` to `Duration`. This avoids an additional error check in new code. * Receive echo in a loop until either the correct ident was received or a timeout occured.
Owner
|
Great work! I have only a small issue which is pointed out up here. And it should be better to add a mutiple thread test case like what you posted on #6 |
aisk
reviewed
Mar 9, 2023
|
|
||
| return Ok(()); | ||
| // if ident is not correct check if timeout is over | ||
| time_elapsed = SystemTime::now().duration_since(time_start).expect("Clock may have gone backwards"); |
Owner
There was a problem hiding this comment.
Since this is a library, call expect is not good here, for it may cause panic for user's process. Return an error will be good.
Contributor
Author
|
Thanks for the review, sounds fine. I am currently a bit occupied, give me a couple of days to update the PR. |
aisk
pushed a commit
that referenced
this pull request
Feb 24, 2024
* Make function std::ping::ping concurrency safe The function `ping` so far did not check the ident received. As a consequence the function `ping` might returned wrong results when used simultaneously from different threads, see #6 for more details. This commit fixes the issue by checking the ident of the reply and comparing it with the expected ident. Changes: * Changed type of `timeout` from `Option<Duration>` to `Duration`. This avoids an additional error check in new code. * Receive echo in a loop until either the correct ident was received or a timeout occured. * feat: improve error handling for duration_since * feat: improve error handling for decode & reply error * Update src/errors.rs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: Michael Hartmann <github@speicherleck.de> Co-authored-by: Manuel Schmidt <ms@manuel-schmidt.at> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Owner
|
These commits is already merged in #19. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The function
pingso far did not check the ident received. As a consequence the functionpingmight returned wrong results when used simultaneously from different threads, see #6 for more details.This commit fixes the issue by checking the ident of the reply and comparing it with the expected ident.
Changes:
timeoutfromOption<Duration>toDuration. This avoids an additional error check in new code.I have tested the changes and they seem to work for me. Let me know if something still needs to be changed.