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(turbo): infinite recursion bug #3019

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions crates/turborepo-lib/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,7 @@ impl RepoState {
}
});

let current_turbo_is_local_turbo = local_turbo_path == current_exe()?;
// If the local turbo path doesn't exist or if we are local turbo, then we go
// ahead and run the Go code linked in the current binary.
if current_turbo_is_local_turbo || !local_turbo_path.try_exists()? {
if should_run_current_turbo(&local_turbo_path)? {
cli::run(Some(self))
} else {
let canonical_local_turbo = local_turbo_path.canonicalize()?;
Expand Down Expand Up @@ -281,6 +278,18 @@ impl RepoState {
}
}

/// If the local turbo path doesn't exist or if we are local turbo, then we go
/// ahead and run the Go code linked in the current binary.
fn should_run_current_turbo(local_turbo_path: &Path) -> Result<bool> {
// Note we must check if local_turbo_path exists before we
// canonicalize the path, otherwise we'll get an error.
if !local_turbo_path.exists() {
return Ok(true);
}

Ok(local_turbo_path.canonicalize()? == current_exe()?.canonicalize()?)
Comment on lines +286 to +290
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we avoid hitting the filesystem twice here?

Suggested change
if !local_turbo_path.exists() {
return Ok(true);
}
Ok(local_turbo_path.canonicalize()? == current_exe()?.canonicalize()?)
match local_turbo_path.canonicalize() {
Ok(local_turbo_path) => Ok(local_turbo_path == current_exe()?.canonicalize()?),
_ => Ok(true),
}

}

/// Checks for `TURBO_BINARY_PATH` variable. If it is set,
/// we do not try to find local turbo, we simply run the command as
/// the current binary. This is due to legacy behavior of `TURBO_BINARY_PATH`
Expand Down