Skip to content
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

Merged
merged 9 commits into from
Aug 14, 2022
Merged

Conversation

hmottestad
Copy link
Contributor

GitHub issue resolved: #4107

Briefly describe the changes proposed in this PR:


PR Author Checklist (see the contributor guidelines for more details):

  • my pull request is self-contained
  • I've added tests for the changes I made
  • I've applied code formatting (you can use mvn process-resources to format from the command line)
  • I've squashed my commits where necessary
  • every commit message starts with the issue number (GH-xxxx) followed by a meaningful description of the change

Comment on lines +47 to +53

/**
* Optional implementation to close this task on a best effort basis.
*/
default void close() {

}
Copy link
Contributor Author

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.

Comment on lines +46 to +56

@Override
public void handleClose() throws QueryEvaluationException {
try {
for (ParallelTask<T> task : tasks) {
task.close();
}
} finally {
super.handleClose();
}
}
Copy link
Contributor Author

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.

Comment on lines +64 to +74

@Override
public void handleClose() throws QueryEvaluationException {
try {
super.handleClose();
} finally {
// signal the phaser to close (if currently being blocked)
phaser.forceTermination();
}
}

Copy link
Contributor Author

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.

Comment on lines +63 to +65
if (ex instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
Copy link
Contributor Author

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.

@hmottestad hmottestad force-pushed the GH-4107-unclosed-iteration-fedx branch from b4a1b12 to 03a22b9 Compare August 4, 2022 07:32
@hmottestad hmottestad merged commit dad350c into main Aug 14, 2022
@hmottestad hmottestad deleted the GH-4107-unclosed-iteration-fedx branch August 14, 2022 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unclosed iteration in fedx
1 participant