Skip to content

Commit

Permalink
[FLINK-18815] Close safety net guarded closeable iff it is still regi…
Browse files Browse the repository at this point in the history
…stered

This closes apache#13124.
  • Loading branch information
kezhuw authored and tillrohrmann committed Aug 13, 2020
1 parent b196912 commit 1ff1266
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,13 @@ String getDebugString() {

@Override
public void close() throws IOException {
closeableRegistry.removeCloseableInternal(innerCloseable);
innerCloseable.close();
// Mark sure the inner closeable is still registered and thus unclosed to
// prevent duplicated and concurrent closing from registry closing. This could
// happen if registry is closing after this phantom reference was enqueued.
if (closeableRegistry.removeCloseableInternal(innerCloseable)) {
LOG.warn("Closing unclosed resource via safety-net: {}", getDebugString());
innerCloseable.close();
}
}
}

Expand Down Expand Up @@ -205,7 +210,6 @@ public void run() {

if (toClose != null) {
try {
LOG.warn("Closing unclosed resource via safety-net: {}", toClose.getDebugString());
toClose.close();
}
catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ protected final void addCloseableInternal(Closeable closeable, T metaData) {
/**
* Removes a mapping from the registry map, respecting locking.
*/
protected final void removeCloseableInternal(Closeable closeable) {
protected final boolean removeCloseableInternal(Closeable closeable) {
synchronized (getSynchronizationLock()) {
closeableToRef.remove(closeable);
return closeableToRef.remove(closeable) != null;
}
}

Expand Down

0 comments on commit 1ff1266

Please sign in to comment.