-
Notifications
You must be signed in to change notification settings - Fork 568
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
Make Input/Scalar AutoCloseable; fix UDF resource leaks #15765
base: master
Are you sure you want to change the base?
Conversation
548a98d
to
24344c5
Compare
Within the `PolyglotScalar` we create a GraalVM polyglot Context that can allocate native resources, these native resources are not automatically released - leading to potential leaks. We didn't notice this with JS as embedded language, but trying to add Python surfaced this issue as the thread leak detection in the test suite triggered. Relevant part from the `Context.close` docs: Closes this context and frees up potentially allocated native resources. A context may not free all native resources allocated automatically. For this reason it is recommended to close contexts after use. If the context is currently being executed on another thread, then an {@link IllegalStateException} is thrown. To close concurrently executing contexts see {@link #close(boolean)}. This is a first, but incomplete step towards addressing the problem: - Makes Input/Scalar closeable - Updates the PolyglotScalar to properly close the context What's incomplete is to go through all the `Input` usages and actually close them after use.
24344c5
to
8adcabd
Compare
@seut @matriv @romseygeek thoughts on this approach? Alternatives:
Currently I'm tending to either the approach in this PR, or 3) |
An alternative to option 1) could be to make TransactionContext implement AutoCloseable, and add a We create transaction contexts in a lot of places so I don't know if it would be any less invasive than making Input closeable. But it feels more like a lifecycle object somehow? |
I kind of prefer @romseygeek's suggestion, or something similar. I'm sceptical regarding the Input solution, when I see this: https://github.com/crate/crate/pull/15765/files#diff-8b855ba352a12dde36505be36a145486feefcc303ab2f45e5c76019b1dd944f6R213 |
There's no way we can force that something gets closed. This problem will exist no matter what. So the main criteria here are:
The life-cycle & responsibility of the transaction context would fit, but looking at how and where we create transaction contexts I don't get the impression that it's much easier to reason about if and where they would get closed. |
Apologies, I didn't phrase it correctly, of course you have to somehow use |
Within the
PolyglotScalar
we create a GraalVM polyglot Context thatcan allocate native resources, these native resources are not
automatically released - leading to potential leaks.
We didn't notice this with JS as embedded language, but trying to add
Python surfaced this issue as the thread leak detection in the test
suite triggered.
Relevant part from the
Context.close
docs:This is a first, but incomplete step towards addressing the problem:
What's incomplete is to go through all the
Input
usages and actuallyclose them after use. (But it would already be an improvement over the status quo, and we could already merge this and iterate on it)