-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-4107 fix unclosed iteration fedx #4108
Conversation
…y finished and does not need the results anymore
|
||
/** | ||
* Optional implementation to close this task on a best effort basis. | ||
*/ | ||
default void close() { | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a new method to the interface to close a task. Closing a task is similar to cancelling a task except that if a closed task is run then it just becomes a no-op instead of throwing an exception like it does if it is cancelled.
|
||
@Override | ||
public void handleClose() throws QueryEvaluationException { | ||
try { | ||
for (ParallelTask<T> task : tasks) { | ||
task.close(); | ||
} | ||
} finally { | ||
super.handleClose(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now try to close all the tasks, since it could be that we have been closed before all the tasks were completed (or even started). There is obviously no guarantee that started tasks can be stopped, so it's all best effort.
…was already cancelled or done
|
||
@Override | ||
public void handleClose() throws QueryEvaluationException { | ||
try { | ||
super.handleClose(); | ||
} finally { | ||
// signal the phaser to close (if currently being blocked) | ||
phaser.forceTermination(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the initial issue. The union() method would deadlock because the phaser was never terminated if the close() method had been called before all the tasks had completed.
There are three other classes that use the same approach with phasers and all those have this exact code.
if (ex instanceof InterruptedException) { | ||
Thread.currentThread().interrupt(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to improve interrupt handling. Other code in RDF4J will typically re-interrupt the current thread if it needs to swallow or wrap an InterruptedException. This means that other code down the line is still able to abort their current execution, which was what the interrupt was initially signalling.
b4a1b12
to
03a22b9
Compare
GitHub issue resolved: #4107
Briefly describe the changes proposed in this PR:
PR Author Checklist (see the contributor guidelines for more details):
mvn process-resources
to format from the command line)