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-1958: fix resource closing in federated service SilentIteration #1959

Conversation

aschwarte10
Copy link
Contributor

The SilenetIteration failed to close the inner iteration, thus resulting
in resource leaks (e.g. pending connections).

Without this fix the attached unit tests takes 20s before forcefully
closing the connection. Now it correctly terminates immediately after
test execution.

Note that additionally a TRACE logger has been introduced to give users
the chance to observe errors.

GitHub issue resolved: #1958

Comment on lines 52 to 56
try {
Iterations.closeCloseable(iter);
} finally {
super.handleClose();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should maybe this also fail silently?

@@ -34,9 +39,20 @@ protected BindingSet getNextElement() throws QueryEvaluationException {
return iter.next();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not required by our styleguide, but I do prefer using { } for if/else/while.

Copy link
Contributor

@abrokenjester abrokenjester Mar 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Actually it is a convention for the RDF4J project, it's just not explicitly enforced by the formatter because in Eclipse, this option is not part of the formatting rules (so I can't make it part of the maven formatter plugin, which uses Eclipse formatter under the hood).

Btw if you're using Eclipse, you can configure it to automatically add braces on save, by going to 'Preferences' -> 'Editor' -> 'Save Actions'. Enable 'Additional actions', click 'Configure...' and in the 'Code Style' dialog enable the option 'Use blocks in if/while/for/do statements'.

Or if you prefer you can use an Eclipse clean up profile to do the same thing.

@@ -19,6 +22,8 @@
*/
public class SilentIteration extends LookAheadIteration<BindingSet, QueryEvaluationException> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only just noticed this after pushing an editorial fix, but apparently we have two SilentIteration classes:

  • org.eclipse.rdf4j.repository.sparql.federation.SilentIteration
  • org.eclipse.rdf4j.query.algebra.evaluation.iterator.SilentIteration

They look identical (barring the fixes you just did) - do we need both or can we get rid of the federated one?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah - to answer my own question, this is probably a deliberate copy to avoid a cyclic dependency.

Let's apply the fix to both copies in this PR. I'll look into a better solution so that we don't have to maintain separate copies separately.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking a bit further, it seems the copy in evaluation.iterator is not actually used anywhere. Let's mark it deprecated, so we can decide to remove it in a later major release.

@abrokenjester
Copy link
Contributor

I will be pushing some fixes to this branch from my end - I need the practice to work with PRs from forked repos from my command line, and if all goes well I can clean this up quickly.

Copy link
Contributor

@abrokenjester abrokenjester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aschwarte10 I've made some changes, basically by introducing a generic SilentIteration class in rdf4j-util and re-using that in the federation code. Let me know what you think.

@abrokenjester abrokenjester self-requested a review March 3, 2020 01:56
Copy link
Contributor Author

@aschwarte10 aschwarte10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing the cleanup! This looks really much better to have the SilentIteration in the util package

@aschwarte10
Copy link
Contributor Author

@aschwarte10 I've made some changes, basically by introducing a generic SilentIteration class in rdf4j-util and re-using that in the federation code. Let me know what you think.

LGTM, thanks for following up

…tIteration

The SilenetIteration failed to close the inner iteration, thus resulting
in resource leaks (e.g. pending connections).

Without this fix the attached unit tests takes 20s before forcefully
closing the connection. Now it correctly terminates immediately after
test execution.

Note that additionally a TRACE logger has been introduced to give users
the chance to observe errors.

Additional changes:

* add braces
* apply fixes to both copies of SilentIteration
* cleaned up different SilentIteration impls
@aschwarte10 aschwarte10 force-pushed the issues/#1958-silent-iteration-close branch from f1c3097 to 783bc42 Compare March 3, 2020 07:36
@aschwarte10
Copy link
Contributor Author

The commits are now squashed into a single one

@aschwarte10 aschwarte10 merged commit c212188 into eclipse-rdf4j:master Mar 3, 2020
@aschwarte10 aschwarte10 deleted the issues/#1958-silent-iteration-close branch March 3, 2020 15:20
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.

SilentIteration in federated services does not always properly close inner resources
3 participants