refreshenv.cmd uses hard-coded temp files
- Dominant language
- C#
- Stars
- 11.5k
- Forks
- 960
- PR merge metrics
- No merged PRs in 30d
Description
### What You Are Seeing?
When running refreshenv at the same time under multiple command prompt windows it tries to write _envset.tmp and _env.cmd but ends up in a race condition situation as the files are locked by other process. This is not an issue when running refreshenv manually but when automating things and optimizing the automation by parallelism.
### What is Expected?
The temp files should be written with random file names.
### How Did You Get This To Happen? (Steps to Reproduce)
Write a script which launches multiple command prompts and runs refreshenv on each.
```cmd
@echo off
start cmd /k refreshenv
start cmd /k refreshenv
```
### Output Log
```
Refreshing environment variables from registry for cmd.exe. Please wait...The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
The process cannot access the file because it is being used by another process.
C:\Users\Administrator\AppData\Local\Temp\_envset.tmp
C:\Users\Administrator\AppData\Local\Temp\_env.cmd
Finished..
```
Contributor guide
Research direction
Inspect refreshenv.cmd and linked pull request 1987, then reproduce the issue with the parallel cmd script shown. Confirm that concurrent refreshenv runs no longer contend over _envset.tmp and _env.cmd, while preserving the existing environment refresh behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- shell
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100