felipecrv commented on code in PR #41232:
URL: https://github.com/apache/arrow/pull/41232#discussion_r1568050006
##########
cpp/src/arrow/filesystem/gcsfs.cc:
##########
@@ -200,6 +201,16 @@ class GcsOutputStream : public arrow::io::OutputStream {
return internal::ToArrowStatus(stream_.last_status());
}
+ Future<> CloseAsync() override {
+ if (closed_) return Status::OK();
+
+ auto self = std::dynamic_pointer_cast<GcsOutputStream>(shared_from_this());
+ auto deferred = [self = std::move(self)]() -> Status { return
self->Close(); };
Review Comment:
> IMO, the CloseAsync() itself cannot be called concurrently or called
multiple times.
It should not but it may be mistakenly called and the `if (closed_)` tests
gives the impression that that code checks against that. We're relying on the
users' discretion.
```cpp
ASSERT_OK_AND_ASSIGN(auto output, fs->OpenOutputStream(path,
/*metadata=*/{}));
ASSERT_OK(output->Write(text.data(), text.size()));
auto close_future = output->CloseAsync();
// It's UB to use `output->...` from here.
// `output->closed_` might be read as `false` by this thread
// even after the I/O thread set it to `true`.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]