Skip to content

Commit

Permalink
apacheGH-41862: [C++][S3] Try out possible fix number 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Jun 6, 2024
1 parent 374b8f6 commit 3f00f91
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cpp/src/arrow/filesystem/s3fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1606,6 +1606,10 @@ class ObjectOutputStream final : public io::OutputStream {
io::internal::CloseFromDestructor(this);
}

std::shared_ptr<ObjectOutputStream> Self() {
return std::dynamic_pointer_cast<ObjectOutputStream>(shared_from_this());
}

Status Init() {
ARROW_ASSIGN_OR_RAISE(auto client_lock, holder_->Lock());

Expand Down Expand Up @@ -1724,9 +1728,9 @@ class ObjectOutputStream final : public io::OutputStream {

RETURN_NOT_OK(EnsureReadyToFlushFromClose());

auto self = std::dynamic_pointer_cast<ObjectOutputStream>(shared_from_this());
// Wait for in-progress uploads to finish (if async writes are enabled)
return FlushAsync().Then([self]() { return self->FinishPartUploadAfterFlush(); });
return FlushAsync().Then(
[self = Self()]() { return self->FinishPartUploadAfterFlush(); });
}

bool closed() const override { return closed_; }
Expand Down Expand Up @@ -1892,6 +1896,9 @@ class ObjectOutputStream final : public io::OutputStream {
}
// Notify completion
if (--state->parts_in_progress == 0) {
// GH-41862: avoid potential deadlock if the Future's callback is called
// with the mutex taken.
lock.unlock();
state->pending_parts_completed.MarkFinished(state->status);
}
}
Expand Down

0 comments on commit 3f00f91

Please sign in to comment.