Fixes #615 Remove expired() to remove race condition #860
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.
Pull Request Details
Presently, there is a race condition where the pointer may be freed
between calling a weak pointer
expired()
and then callinglock()
results in a null pointer being returned. This results in a segfault in the
function expecting a non null function.
Description
This change was required because this race condition did come up in
practice resulting in segfaults. The following is one
such segfault in
libusb_device_list_impl()
, which expects a pointerto the session to be non null.
Code expecting a non-null session (
sess
):The stack trace:
The following is the exact location (
->
) where the segfault occurs in the assembly.You will note that the assembly line corresponds to the dereference of the
sess
pointer.
Changes were made in accordance to how CPP reference suggests dealing
with weak pointers: https://en.cppreference.com/w/cpp/memory/weak_ptr/lock
Related Issue
#615
Which devices/areas does this affect?
This affects all devices as the code for checking a USRP exists
is not limited to if one has the USRP. I have managed to get it
to segfault without any device connected at all!
Testing Done
Since this is a race condition, one needs to luck out with the timing
such that the pointer is freed between
expired()
andlock()
. Theerror could occur in 5 minutes or 5 hours.
To test the change, I repeatedly called
uhd_usrp_find
for severalswithout any segfaults.
Checklist
MPM compat, noc_shell, specific RFNoC block, ...)