Repository navigation
GH-36523: [C++] Fix TSan-detected lock ordering issues in S3 - #36536
Conversation
|
Can you run this with your stress test @westonpace ? |
|
|
|
|
There was a problem hiding this comment.
TBH I'm not sure if calling std::move here is enough to destroy client_lock at the end of this statement. @bkietz Can you advise?
There was a problem hiding this comment.
std::move will not destroy this lock (in general, it's useful to think of std::move as doing nothing except flagging a reference as legal to move construct from). What you want here is
| auto outcome = std::move(client_lock)->HeadObject(req); | |
| S3Model::HeadObjectOutcome outcome; | |
| { | |
| ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock()); | |
| outcome = std::move(client_lock)->HeadObject(req); | |
| } // client lock goes out of scope here |
or maybe
| auto outcome = std::move(client_lock)->HeadObject(req); | |
| ARROW_ASSIGN_OR_RAISE(auto outcome, holder_->Lock().Map([&](auto client_lock) { | |
| return client_lock->HeadObject(req); | |
| })); |
There was a problem hiding this comment.
Or you might even prefer
template <auto MemberPtr, typename... Args>
auto S3ClientHolder::LockThenCall(Args&&... args) {
return Lock().Map([&](S3ClientLock client_lock) {
return (client_lock.get()->*MemberPtr)(std::forward<Args>(args)...);
});
}used like
| auto outcome = std::move(client_lock)->HeadObject(req); | |
| ARROW_ASSIGN_OR_RAISE(auto outcome, holder_->LockThenCall<&S3Client::HeadObject>(req)); |
There was a problem hiding this comment.
Ok, I opted for a more manual approach because mixing arrow::Result and Aws::Outcome is not really convenient:
https://github.com/apache/arrow/pull/36536/files#diff-27b767cd06b879c40106ea98d21d3b12f13ec6e9f9aa49218d10583c5c1899c4R725-R726
S3ClientLock Move() { return std::move(*this); } auto deferred = [owned_buffer, holder = holder_, req = std::move(req),
state = upload_state_,
part_number = part_number_]() mutable -> Status {
ARROW_ASSIGN_OR_RAISE(auto client_lock, holder->Lock());
auto outcome = client_lock.Move()->UploadPart(req);
HandleUploadOutcome(state, part_number, req, outcome);
return Status::OK();
};|
@github-actions crossbow submit -g cpp |
This comment was marked as outdated.
This comment was marked as outdated.
|
@github-actions crossbow submit -g cpp |
This comment was marked as outdated.
This comment was marked as outdated.
|
@raulcd Ideally we would have this PR in the release, because it fixes a late regression (we're not sure the regression can happen concretely, though). |
|
@github-actions crossbow submit -g python -g wheel |
This comment was marked as outdated.
This comment was marked as outdated.
westonpace
left a comment
There was a problem hiding this comment.
I'll wait for this to merge and then update #35440 . The approach there will need to change as it currently holds the client lock for the duration of the request and since DeleteDirContents calls GetFileInfo this will be a problem. However, it should be easy enough to change it back to locking on the spot when needed.
|
@github-actions crossbow submit -g python -g wheel -g cpp |
|
Revision: 85a0144 Submitted crossbow builds: ursacomputing/crossbow @ actions-1735f0c98a |
|
|
|
@westonpace Are you available quickly for review? |
kou
left a comment
There was a problem hiding this comment.
+1
(I don't know why S3ClinetLock::Move() works but LGTM if it works as we expect.)
|
I'll rebase this into #35440 now and run my stress tests |
|
+1, after running my test multiple times with and without CPU stress I no longer see any TSAN errors. I've included one minor comment tweak in #35440 |
|
Great, thank you @westonpace :-) |
|
After merging your PR, Conbench analyzed the 6 benchmarking runs that have been run so far on merge-commit 8eacd8c. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. It also includes information about possible false positives for unstable benchmarks that are known to sometimes produce them. |
It is counter-intuitive, but lock ordering issues can happen even with a shared mutex locked in shared mode.
The reason is that locking again in shared mode can block while there are threads waiting to take the lock in exclusive mode. For this reason, we must avoid to keep the S3ClientLock taken before is it taken again.