Skip to content

Prevent runBlocking failure when the Worker it runs on terminates #3585

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

Merged
merged 2 commits into from
Jan 17, 2023

Conversation

dkhalanskyjb
Copy link
Collaborator

Fixes #3578

A competitor to #3584

@dkhalanskyjb dkhalanskyjb requested a review from qwwdfsad January 12, 2023 12:02
@dkhalanskyjb dkhalanskyjb changed the title Prevent runBlocking failing when the Worker it runs on terminates Prevent runBlocking failure when the Worker it runs on terminates Jan 12, 2023
fun keepAlive() {
Worker.current.executeAfter(afterMicroseconds = 100_000) {
if (!isCompleted) {
keepAlive()
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really fond of this change.
It has really weird semantics "let's invoke something on a regular basis to workaround the issue that only reproduces during termination", it interferes with nested runBlockings (producing probably unnecessary tasks) and opens a can of worms for "what happens if 'start' or 'joinBlocking' throw system exception (e.g. OOM)". For now it seems it will create a task that is just stuck forever

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are all good points, I fixed the code accordingly.

Regarding the weird semantics, I don't see anything weird about it. You could say, "to workaround the issue that only reproduces during termination" about any mechanism that recognizes something canceling or closing, yet such code is common. Here, we're just explicitly making sure the worker knows further work will be expected from it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also, "keepalive" is a common term denoting exactly this approach, though from a different IT area: https://en.wikipedia.org/wiki/Keepalive

@dkhalanskyjb dkhalanskyjb requested a review from qwwdfsad January 13, 2023 12: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.

2 participants