Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.

Conversation

@chkeita
Copy link
Contributor

@chkeita chkeita commented Aug 2, 2023

Summary of the Pull Request

The default behavior or the runtime is wait for all spawned work to be done before exiting. This was causing the task to hang when exiting.
This change adds a force shutdown at the end of the main function of the task.

closes #3377

@chkeita chkeita requested review from Porges and tevoinea August 2, 2023 01:54
Copy link
Member

@tevoinea tevoinea left a comment

Choose a reason for hiding this comment

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

Just to help me better understand:

  • We'll never call rt.shutdown_background() until let result = rt.block_on(run(matches)); completes
  • run(matches) will only complete when one of the futures complete from this select! macro
    let result = tokio::select! {
    result = config.run() => result,
    // Ignore this task if it returns due to a querying error.
    Ok(oom) = check_oom => {
    // Convert the OOM notification to an error, so we can log it below.
    let err = format_err!("out of memory: {} bytes available, {} required", oom.available_bytes, oom.min_bytes);
    Err(err)
    },
    _shutdown = shutdown_listener => {
    Ok(())
    }
    };
  • select! claims to cancel the remaining branches

Waits on multiple concurrent branches, returning when the first branch completes, cancelling the remaining branches.

Does that mean the cancellation from select! happens in the background? And that prior to this PR, we wait for the cancellation to complete when we drop the runtime?

@chkeita
Copy link
Contributor Author

chkeita commented Aug 2, 2023

Does that mean the cancellation from select! happens in the background? And that prior to this PR, we wait for the cancellation to complete when we drop the runtime?

This is not necessarily a problem with select!. The tokio docs says it waits on all the spawned work. Select will cancel everything related the task itself But something was spawned inside that task of it becomes an independent branch that is not waited on.

@chkeita chkeita merged commit 4c6fb7a into microsoft:main Aug 2, 2023
AdamL-Microsoft added a commit that referenced this pull request Aug 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tasks hangs when shutting down

3 participants