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

Explicitly exit at end of execution #398

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kjrokos
Copy link
Contributor

@kjrokos kjrokos commented Jan 9, 2025

Resolves #359

Notes from investigation:

  • OkHttp has the hanging issue, but the exact same code (as close as Ktor allows, which is quite close) using the Cio engine does not.
  • In both cases, the server gets the result back in approximately the same amount of time. The hanging occurs after all other execution is finished.
  • In the OkHttp case, the culprit appears to be an "OkHttp Dispatcher" thread that is still running. I've found a good number of issues related to this, but all from around ~2020 and claim be resolved in the versions we are using (e.g., https://youtrack.jetbrains.com/issue/KTOR-396)
  • I tried manually closing the client, engine, dispatcher, executor, connection pool, etc - with no success. As near as I can tell, closing just the client should be sufficient, but clearly isn't in our case
  • If I run the exact same code outside of a container, I don't have this problem. I don't know what is different about the container environment. It's also possible (maybe?) that there is a thread sticking around longer but it's not noticeable because the system itself isn't waiting on it to close. But I'm not sure how to test that, and it seems unlikely.
  • If we explicitly call 'System.exit(0)' at the end of collection, everything works as expected. I don't love it, but this is likely the best (and most general) solution. The user shouldn't be doing anything at this point - any cleanup should have already happened, all results have already been sent back to the server, and the user would expect that the program exits here immediately anyway.
  • I don't know if the issue can present itself in Python in the same way, but I have added exits at the same place in the Python templates for consistency

@kjrokos kjrokos added this to the 1.2 milestone Jan 9, 2025
@kjrokos kjrokos requested a review from MarkArbogast January 9, 2025 20:19
@kjrokos kjrokos self-assigned this Jan 9, 2025
@kjrokos kjrokos force-pushed the fix/359-hanging-collection branch from 1c1d34e to 6369a02 Compare January 9, 2025 20: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.

Java SDK testConnection additional latency of ~1min added
1 participant