Uh oh!
There was an error while loading. Please reload this page.
GH-3205: Make HadoopPositionOutputStream.close() safe to call even if closed - #3206
Conversation
wgtmac
commented
Apr 30, 2025
If #3204 is merged, do we still need this fix? |
dominicso
commented
Apr 30, 2025
steveloughran
left a comment
There was a problem hiding this comment.
hadoop streams are meant to have close() idempotent, it is hflush() which is failing here as that is the strict call. Even with a switch to flush() things may have problems.
I think this needs a test, even just for local file output, calling close() twice, ideally on separate threads.
Is there one?
| @Override | ||
| public void close() throws IOException { | ||
| if (closed) { |
There was a problem hiding this comment.
safest to use an atomic bool here
if (closed.getAndSet(true) { return;
}
streams are nominally not thread safe, but cross stream use happens. Making close() itself thread safe is low cost and avoids problems on cleanup
There was a problem hiding this comment.
Changed to use AtomicBoolean
steveloughran
commented
May 1, 2025
just looked at flush() implementations s3a: tells you off abfs: probably raises overall then: dangerous to call flush() on a closed stream. Wrapping it is safer |
wgtmac
commented
May 2, 2025
Thanks @dominicso@steveloughran! #3204 is merged. Let's rebase this PR. |
dominicso
commented
May 7, 2025
Rebased and changed to use AtomicBoolean.
@steveloughran If a test is added to use local file output, wouldn't it use Looking at |
wgtmac
commented
May 10, 2025
Merged. Thanks @dominicso and @steveloughran! |
Rationale for this change
HadoopPositionOutputStream implements Closable, so its close method should have no effect if already closed.
What changes are included in this PR?
Add code to HadoopPositionOutputStream.close() to check if already closed. If yes, do nothing.
Are these changes tested?
Expecting test runner to do this.
Are there any user-facing changes?
No
Closes#3205