Open rhaas80 opened 3 years ago
Good catch! We should add a wrapper function that gets the kvtree and handles the locking, like:
- kvtree* file_list = axl_kvtrees[id];
+ kvtree* file_list = get_kvtree(id);
If there is no objection I will try and give adding correct locking code, using a get_kvtree
function plus locking for access to the other global variables a try.
Branch https://github.com/rhaas80/AXL/tree/rhaas/locks contains an implementation protecting against the race condition. Changes are: https://github.com/rhaas80/AXL/compare/rhaas/keyvalue...rhaas80:rhaas/locks
Implementation notes:
axl_kvtrees
but not the other global variables (that hold configuration options), since the latter are only accessed in the main thread so those do not share a race conditionAXL_Config
on a transfer that has already been dispatch is a race condition (since there is no lock on the individual file_list
kvtrees) and not supportedAXL_Config
for the DEBUG settings is race condition (since axl_debug
is not protected but is accessed from within the worker threads) while there are already dispatched transfers and will not be fixed@rhaas80 could you open a PR with those changes?
@rhaas80 could you open a PR with those changes?
Well it would be a pull request onto my own rhaas/keyvalue branch which itself still needs to be approved. So I can make it a work-in-progress. An actual pull does not make much sense.
Here's a pull request, but as said it does not make that much sense to pull into my own branch. https://github.com/rhaas80/AXL/pull/1
In
https://github.com/ECP-VeloC/AXL/blob/a799cd9b7a406a80173ecb2bf3a32000f432f8ce/src/axl_pthread.c#L321
axl_kvtrees
is accessed without protecting from race conditions.Looking eg at https://github.com/ECP-VeloC/AXL/blob/a799cd9b7a406a80173ecb2bf3a32000f432f8ce/src/axl.c#L98
where one has
it seems clear that
axl_kvtress
is accessed in a multi-threaded context. Sincerealloc
can move the block of data when allocating memory ie innew_ptr = realloc(old_ptrs, new_size)
there is no guarantee thatnew_ptr == old-ptr
one must not assume thataxl_kvtrees[id]
is accessible without the lock.