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 May 29, 2024
1 parent 4a2df66 commit eaa0a56
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 @@ -1569,6 +1569,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 @@ -1687,9 +1691,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 @@ -1855,6 +1859,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 eaa0a56

Please sign in to comment.