fix: remove os.Chdir from aspire server InitializeAsync#7362
fix: remove os.Chdir from aspire server InitializeAsync#7362
Conversation
Replace global os.Chdir(rootPath) with explicit path passing to avoid mutating process-wide working directory. This is safer for concurrent operations and eliminates ambient authority. Fixes #3288 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Removes process-wide working-directory mutation from the VS RPC server initialization to eliminate ambient authority and reduce concurrency hazards for multi-session scenarios.
Changes:
- Removed
os.Chdir(rootPath)(and related TODO) fromserverService.InitializeAsync. - Removed now-unused
osimport fromserver_service.go.
Comments suppressed due to low confidence (1)
cli/azd/internal/vsrpc/server_service.go:39
- With os.Chdir(rootPath) removed, InitializeAsync no longer validates that rootPath exists/is a directory. That means an empty/invalid rootPath can successfully create a session and only fail later (or cause commands to run under the server process’ current working directory when GlobalCommandOptions.Cwd is set). Consider explicitly validating rootPath here (non-empty + os.Stat + IsDir) and returning a contextual error if it’s invalid.
return nil, err
}
session.rootPath = rootPath
session.rootContainer = s.server.rootContainer
Azure Dev CLI Install InstructionsInstall scriptsMacOS/Linux
bash: pwsh: WindowsPowerShell install MSI install Standalone Binary
MSI
Documentationlearn.microsoft.com documentationtitle: Azure Developer CLI reference
|
Summary
Fixes #3288
Removes the
os.Chdir(rootPath)call from aspire server'sInitializeAsyncinserver_service.go. This was an ambient authority pattern that mutated process-wide working directory, which is unsafe for concurrent operations.Changes
server_service.go— Removedos.Chdir(rootPath)and its TODO comment. Removed unusedosimport.Why This Is Safe
rootPathis already passed explicitly everywhere it's needed:CwdinGlobalCommandOptions(deploy/provision)HostProjectPathinRequestContext(debug, aspire, environment services)internal/vsrpc/usesos.Getwd()or relies on process working directoryTesting
go test ./internal/vsrpc/... -short -count=1