Repository navigation
Enable Add-Content to share read access to other tools while writing content - #8091
Conversation
924280e to
777f23f
Compare
| } | ||
| } | ||
|
|
||
| Describe "Add-Content feature tests" -Tag Feature { |
There was a problem hiding this comment.
We always have problems with async tests. Do we really need the test? I'd only add an comment in C# code.
There was a problem hiding this comment.
I kind of agree on async tests being inherently fragile. Perhaps for this one a comment in the code is sufficient.
There was a problem hiding this comment.
Can make it sync:
- open a file with
FileStream(FileAccess.Read, FileShare.ReadWrite)and keep it open. - run new
Add-Content(withFileAccess.Write, FileShare.ReadWrite) - close
FileStreamfrom 1). The test should not throw.
The old Add-Content (with FileShare.Write) in 2) would throw.
There was a problem hiding this comment.
Good suggestion, let me see if that repros the original issue.
There was a problem hiding this comment.
Please see if these changes are possible. It would harden the test.
There was a problem hiding this comment.
Andrew (@anmenaga) that worked perfectly and so simple :)
| $writer = Start-Job -ScriptBlock { | ||
| param($logpath) | ||
|
|
||
| 1..10 | % { |
There was a problem hiding this comment.
Use ForEach-Object instead of %
There was a problem hiding this comment.
is (1..10).foreach{...} faster then ForEach-Object?
…ows script tests wait for precheck-windows' background cases start ensure-docker.ps1 in another PowerShell process, append each line it prints to a log with Add-Content, and poll that log every 200 ms. Windows PowerShell 5.1's Add-Content opens the file with FileShare.Write (PowerShell 6.2 changed it, PowerShell/PowerShell#8091), so an append that meets the case's read fails with "being used by another process" on a stderr nobody reported, and the line is lost. When it is the line the case waits for, the case waits out its deadline: 7 failures since 2026-10-02, all "did not say it was waiting within N s", each at its deadline. Every writer of a file a case polls now appends through Add-Line, which shares the file with readers and reports a failed write without throwing, so a lost diagnostic line can never change the fake docker's answer. Failing background cases now report the process's stderr, and the cases that wait on another runner's marker also report the docker calls made and the marker lookups. No deadline, assertion or case changed. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
…ows script tests wait for (#4725) precheck-windows' background cases start ensure-docker.ps1 in another PowerShell process, append each line it prints to a log with Add-Content, and poll that log every 200 ms. Windows PowerShell 5.1's Add-Content opens the file with FileShare.Write (PowerShell 6.2 changed it, PowerShell/PowerShell#8091), so an append that meets the case's read fails with "being used by another process" on a stderr nobody reported, and the line is lost. When it is the line the case waits for, the case waits out its deadline: 7 failures since 2026-10-02, all "did not say it was waiting within N s", each at its deadline. Every writer of a file a case polls now appends through Add-Line, which shares the file with readers and reports a failed write without throwing, so a lost diagnostic line can never change the fake docker's answer. Failing background cases now report the process's stderr, and the cases that wait on another runner's marker also report the docker calls made and the marker lookups. No deadline, assertion or case changed. Signed-off-by: slayerjain <shubhamkjain@outlook.com>
PR Summary
Add-Contentuses a writer that currently sets share access to write. So if using a tool liketailto read a log file while trying to write to it will fail. Fix is to change share access to readwrite which will allow other processes to continue to read from it while the writer writes new content.Fix #5924
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:to the beginning of the title and remove the prefix when the PR is ready.[feature]if the change is significant or affects feature tests