Skip to content

fix: lookupExecutable race condition#87

Merged
AndrewBarba merged 5 commits intotuist:mainfrom
AndrewBarba:fix-lookup-race-condition
Aug 15, 2024
Merged

fix: lookupExecutable race condition#87
AndrewBarba merged 5 commits intotuist:mainfrom
AndrewBarba:fix-lookup-race-condition

Conversation

@AndrewBarba
Copy link
Copy Markdown
Collaborator

@AndrewBarba AndrewBarba commented Aug 13, 2024

I was seeing inconsistent behavior in lookupExectuable do to a race condition where the data was read before waiting for the task to finish.

This PR fixes the race condition by ensuring we wait for process exit before attempting to read data from the pipe

I also changed the signature of lookupExecutable to either return a URL or throw. I removed the possible nil which would simply surface as a thrown error later on anyway

@AndrewBarba AndrewBarba requested a review from pepicrft August 13, 2024 20:52
Comment thread Sources/Command/Command.swift Outdated

#if os(Windows)
command = "where"
command = "C:\\Windows\\System32\\where.exe"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good catch!

Comment on lines +263 to +264
process.environment = ProcessInfo.processInfo.environment
process.currentDirectoryURL = URL(fileURLWithPath: FileManager.default.currentDirectoryPath)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wrongly assumed those values would be inherited 😅. Good catch @AndrewBarba

AndrewBarba and others added 3 commits August 15, 2024 09:59
Co-authored-by: Pedro Piñera Buendía <663605+pepicrft@users.noreply.github.com>
@AndrewBarba AndrewBarba merged commit 5df99fd into tuist:main Aug 15, 2024
@AndrewBarba AndrewBarba deleted the fix-lookup-race-condition branch August 15, 2024 14:04
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.

2 participants