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

Use an isolated clone of the Session in workunit handlers to shield against cancellation #11721

Merged
merged 2 commits into from
Mar 17, 2021

Conversation

stuhood
Copy link
Member

@stuhood stuhood commented Mar 17, 2021

Problem

As described in #11715, streaming workunit handler callbacks currently use the same Session object as is used in the foreground because they need access to the metrics generated there. But this means that they have the same UI settings as the foreground, and when the foreground is cancelled, they are too.

Solution

Split the Session object into SessionHandle and SessionState to allow for a shallow clone of the Session that is isolated in terms of cancellation and UI.

Then, use an isolated_shallow_clone in the StreamingWorkunitHandler so that it can continue to consume metrics and execute work (without a UI) after the client has gone away.

Result

Fixes #11715.

[ci skip-build-wheels]

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
…d be associated with a Session but not canceled by it.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@stuhood
Copy link
Member Author

stuhood commented Mar 17, 2021

The commits are useful to review independently.

Copy link
Contributor

@Eric-Arellano Eric-Arellano left a comment

Choose a reason for hiding this comment

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

Excellent! Thanks Stu.

Comment on lines +1398 to +1402
fn session_isolated_shallow_clone(py: Python, session_ptr: PySession) -> CPyResult<PySession> {
with_session(py, session_ptr, |session| {
PySession::create_instance(py, session.isolated_shallow_clone())
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, I am curious if we'll be able to move free functions like this onto methods defined on PySession? Totally okay to not do in this PR - it's a followup project I want to explore to see if it further simplifies our FFI.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we probably can. The with_$x context managers add a bunch of noise, and are much less central than calling allow_threads, which we should try to do in nearly all cases.

Copy link
Member Author

Choose a reason for hiding this comment

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

Opened #11722

Copy link
Contributor

@tdyas tdyas left a comment

Choose a reason for hiding this comment

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

lgtm

@stuhood stuhood merged commit e64cf31 into pantsbuild:master Mar 17, 2021
@stuhood stuhood deleted the stuhood/shallow-session-clone branch March 17, 2021 19:51
@benjyw benjyw mentioned this pull request Mar 20, 2021
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.

Async streaming workunit handlers are cancelled when the client goes away
3 participants