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

Fix risk of dangling workunits by using in_workunit! macro #11759

Merged
merged 10 commits into from
Jun 8, 2021

Conversation

stuhood
Copy link
Sponsor Member

@stuhood stuhood commented Mar 21, 2021

Fixes #11548.

…workunit while it runs.

[ci skip-build-wheels]
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Comment on lines 825 to 833
#[macro_export]
macro_rules! in_workunit {
($workunit_store: expr, $workunit_name: expr, $workunit_metadata: expr, |$workunit: ident| async move { $( $body:tt )* }) => (
{
let (store_handle, mut $workunit) = $crate::_start_workunit($workunit_store, $workunit_name, $workunit_metadata);
$crate::scope_task_workunit_store_handle(Some(store_handle), async move {
let result = {
let $workunit = &mut $workunit;
async move { $( $body )* }
Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

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.

Macro looks good. Will this suffer from the stack overflow issue / needing to box the future?

@stuhood
Copy link
Sponsor Member Author

stuhood commented Mar 23, 2021

Macro looks good. Will this suffer from the stack overflow issue / needing to box the future?

This should not add to the stack size in a significant way, afaict... if my understanding is correct then this should only add twoish variables to the stack: the workunit, and the workunit store handle.

@Eric-Arellano

This comment has been minimized.

# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
Comment on lines -473 to -480
let response = with_workunit(
context.workunit_store.clone(),
"check_action_cache".to_owned(),
WorkunitMetadata {
level: Level::Trace,
desc: Some(format!("check action cache for {:?}", action_digest)),
..WorkunitMetadata::default()
},
Copy link
Contributor

Choose a reason for hiding this comment

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

This work unit was moved to remote.rs in check_action_cache, which is where all the counters are incremented

///
/// NB: Public for macro usage: use the `in_workunit!` macro.
///
pub fn _start_workunit(
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how best to factor the macro with its two arms. For example, perhaps this function should no longer exist and we should inline. We could have one arm call the other for DRY.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

I think that it's ok for now. If it grows at all can DRY it up.

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

@stuhood stuhood left a comment

Choose a reason for hiding this comment

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

Looks great, thanks! I can't shipit because I started it. But if you shipit I'll merge.

src/rust/engine/process_execution/src/remote_cache.rs Outdated Show resolved Hide resolved
///
/// NB: Public for macro usage: use the `in_workunit!` macro.
///
pub fn _start_workunit(
Copy link
Sponsor Member Author

Choose a reason for hiding this comment

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

I think that it's ok for now. If it grows at all can DRY it up.

@stuhood stuhood marked this pull request as ready for review June 8, 2021 16:24
# Building wheels and fs_util will be skipped. Delete if not intended.
[ci skip-build-wheels]
@Eric-Arellano Eric-Arellano changed the title Add a macro to allow incrementing metrics directly on a workunit Fix risk of dangling workunits by using in_workunit! macro Jun 8, 2021
@Eric-Arellano
Copy link
Contributor

FYI I updated the PR title to reflect the change in scope from the original draft PR.

cache_lookup_start: Instant,
action_digest: Digest,
mut local_execution_future: BoxFuture<'_, Result<FallibleProcessResultWithPlatform, String>>,
) -> Result<(FallibleProcessResultWithPlatform, bool), String> {
Copy link
Contributor

@tdyas tdyas Jun 8, 2021

Choose a reason for hiding this comment

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

Would it be better to use a tuple struct here so that the bool has a name?

Copy link
Contributor

Choose a reason for hiding this comment

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

Change "tuple struct" to just "struct" -- I meant the one that has names ...

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 -- no need to block on my question about tuple vs struct

@stuhood stuhood merged commit af5fad7 into pantsbuild:main Jun 8, 2021
@stuhood stuhood deleted the stuhood/workunit-macro branch June 8, 2021 18:31
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.

Counters can have dangling pointers to workunits
4 participants