-
-
Notifications
You must be signed in to change notification settings - Fork 951
fix(task): prevent hang when nested tasks fail #6430
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| # https://github.com/jdx/mise/discussions/6391 | ||
|
|
||
| cat <<EOF >mise.toml | ||
| [tasks.fails] | ||
| run = ''' | ||
| sleep 1; | ||
| echo "An error occurred!" | ||
| exit 1; | ||
| ''' | ||
|
|
||
| [tasks.deponfails] | ||
| depends = ["fails"] | ||
| run = 'echo "This will not run because the dependency fails."' | ||
|
|
||
| [tasks.grouped] | ||
| run = [ | ||
| { task = "deponfails" } | ||
| ] | ||
| EOF | ||
|
|
||
| # Test that task failure with dependencies does not hang | ||
| timeout 5s mise run grouped 2>&1 && exit_code=0 || exit_code=$? | ||
|
|
||
| # Check if it was a timeout (exit code 124) | ||
| if [ "$exit_code" -eq 124 ]; then | ||
| echo "FAIL: Task hung after dependency failure (timeout reached)" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # The command should fail with exit code 1 | ||
| if [ "$exit_code" -ne 1 ]; then | ||
| echo "Expected exit code 1, got $exit_code" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Test passed: task with failing dependency did not hang" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -829,7 +829,7 @@ impl Run { | |
| let sub_deps = Arc::new(Mutex::new(sub_deps)); | ||
|
|
||
| // Pump subgraph into scheduler and signal completion via oneshot when done | ||
| let (done_tx, done_rx) = oneshot::channel::<()>(); | ||
| let (done_tx, mut done_rx) = oneshot::channel::<()>(); | ||
| let task_env_directives: Vec<EnvDirective> = | ||
| task_env.iter().cloned().map(Into::into).collect(); | ||
| { | ||
|
|
@@ -887,10 +887,40 @@ impl Run { | |
| }); | ||
| } | ||
|
|
||
| // Wait for completion | ||
| done_rx.await.map_err(|e| eyre!(e))?; | ||
| // Wait for completion with a check for early stopping | ||
| loop { | ||
| // Check if we should stop early due to failure | ||
| if self.is_stopping() && !self.continue_on_error { | ||
| trace!("inject_and_wait: stopping early due to failure"); | ||
| // Clean up the dependency graph to ensure completion | ||
| let mut deps = sub_deps.lock().await; | ||
| let tasks_to_remove: Vec<Task> = deps.all().cloned().collect(); | ||
| for task in tasks_to_remove { | ||
| deps.remove(&task); | ||
| } | ||
| drop(deps); | ||
| // Give a short time for the spawned task to finish cleanly | ||
| let _ = tokio::time::timeout(Duration::from_millis(100), done_rx).await; | ||
|
||
| return Err(eyre!("task sequence aborted due to failure")); | ||
| } | ||
|
|
||
| // Try to receive the done signal with a short timeout | ||
| match tokio::time::timeout(Duration::from_millis(100), &mut done_rx).await { | ||
| Ok(Ok(())) => { | ||
| trace!("inject_and_wait: received done signal"); | ||
| break; | ||
| } | ||
| Ok(Err(e)) => { | ||
| return Err(eyre!(e)); | ||
| } | ||
| Err(_) => { | ||
| // Timeout, check again if we should stop | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Check if we failed during the execution | ||
| // Final check if we failed during the execution | ||
| if self.is_stopping() && !self.continue_on_error { | ||
| return Err(eyre!("task sequence aborted due to failure")); | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cleanup code holds the lock while collecting all tasks and then iterates through them. Consider clearing the dependency graph more efficiently with a single operation like
deps.clear()if available, or release the lock between collection and removal to reduce lock contention.