From c48d59ada2e20d4d5e4584feeca0370050b24d08 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Mon, 10 Jun 2024 16:00:18 +0200 Subject: [PATCH] Make sure future is accessed in a thread-safe way. --- cpp/src/arrow/filesystem/s3fs.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cpp/src/arrow/filesystem/s3fs.cc b/cpp/src/arrow/filesystem/s3fs.cc index 9862845ff8b1c..99cee19ed1e78 100644 --- a/cpp/src/arrow/filesystem/s3fs.cc +++ b/cpp/src/arrow/filesystem/s3fs.cc @@ -1898,8 +1898,13 @@ class ObjectOutputStream final : public io::OutputStream { if (--state->parts_in_progress == 0) { // GH-41862: avoid potential deadlock if the Future's callback is called // with the mutex taken. + auto fut = state->pending_parts_completed; lock.unlock(); - state->pending_parts_completed.MarkFinished(state->status); + // State could be mutated concurrently if another thread writes to the + // stream, but in this case the Flush() call is only advisory anyway. + // Besides, it's not generally sound to write to an OutputStream from + // several threads at once. + fut.MarkFinished(state->status); } }