Repository navigation
Fix Windows rewatch CI flakes from files opened without delete sharing #9034
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
Merged
+160
−22
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
314e53f
Open files with delete sharing on Windows
cknitt a1da0c0
Retry removing watch.lock and stop a watcher that ignores it
cknitt 94ef5ea
Diagnose Windows rewatch CI failures that leave no evidence
cknitt c5694c7
Serialize writes to the compiler call log
cknitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| - On Windows, let other programs delete or rename files while the build system reads them, so stopping a watcher by removing `lib/watch.lock` no longer fails intermittently. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Source this file and call start_process_watchdog to run the rest of the | ||
| # shell under windows_process_watchdog.ps1. It does nothing on other systems. | ||
| # The shell exits with status 1 when the watchdog had to stop processes. | ||
|
|
||
| start_process_watchdog() { | ||
| case "${RUNNER_OS:-}" in | ||
| Windows) ;; | ||
| *) return 0 ;; | ||
| esac | ||
| watchdog_dir=$(mktemp -d) | ||
| export WATCHDOG_RUNNING="$watchdog_dir/running" | ||
| export WATCHDOG_REPORT="$watchdog_dir/report" | ||
| : >"$WATCHDOG_RUNNING" | ||
| powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass \ | ||
| -File "$(dirname "${BASH_SOURCE[0]}")/windows_process_watchdog.ps1" & | ||
| trap stop_process_watchdog EXIT | ||
| } | ||
|
|
||
| stop_process_watchdog() { | ||
| local status=$? | ||
| rm -f "$WATCHDOG_RUNNING" | ||
| if [ -s "$WATCHDOG_REPORT" ]; then | ||
| echo "::error::The process watchdog stopped runaway test processes:" | ||
| cat "$WATCHDOG_REPORT" | ||
| status=1 | ||
| fi | ||
| rm -rf "$watchdog_dir" | ||
| exit "$status" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Stops runaway test processes before they starve the CI runner. Hosted | ||
| # Windows runners that run out of memory lose contact with GitHub and leave no | ||
| # log at all, so report the largest processes and stop the test processes | ||
| # while the runner can still upload the log. | ||
| # | ||
| # Runs until the file named by WATCHDOG_RUNNING is removed. Writes its report | ||
| # to the file named by WATCHDOG_REPORT. | ||
|
|
||
| $names = 'rescript', 'rescript-rust', 'bsc' | ||
| $perProcessLimit = 3GB | ||
| $countLimit = 64 | ||
| $minimumFree = 1.5GB | ||
|
|
||
| function Describe-Processes($processes) { | ||
| $processes | | ||
| Sort-Object WorkingSet64 -Descending | | ||
| Select-Object -First 15 | | ||
| ForEach-Object { | ||
| $process = Get-CimInstance Win32_Process -Filter "ProcessId=$($_.Id)" -ErrorAction SilentlyContinue | ||
| '{0,7} parent {1,7} {2,8:N0} MB {3,9:N1} s CPU {4}' -f ` | ||
| $_.Id, $process.ParentProcessId, ($_.WorkingSet64 / 1MB), $_.CPU, ` | ||
| $(if ($process.CommandLine) { $process.CommandLine } else { $_.ProcessName }) | ||
| } | ||
| } | ||
|
|
||
| while (Test-Path -LiteralPath $env:WATCHDOG_RUNNING) { | ||
| Start-Sleep -Seconds 5 | ||
| $tested = @(Get-Process -Name $names -ErrorAction SilentlyContinue) | ||
| if ($tested.Count -eq 0) { continue } | ||
| $free = (Get-CimInstance Win32_OperatingSystem).FreePhysicalMemory * 1KB | ||
| $reason = $null | ||
| $large = @($tested | Where-Object { $_.WorkingSet64 -gt $perProcessLimit }) | ||
| if ($large.Count -gt 0) { | ||
| $reason = "process $($large[0].Id) uses $([int]($large[0].WorkingSet64 / 1MB)) MB" | ||
| } elseif ($tested.Count -gt $countLimit) { | ||
| $reason = "$($tested.Count) rescript/bsc processes are running" | ||
| } elseif ($free -lt $minimumFree) { | ||
| $reason = "free memory is down to $([int]($free / 1MB)) MB" | ||
| } | ||
| if ($reason) { | ||
| $report = @("Process watchdog: $reason; stopping rescript/bsc processes.") + | ||
| 'Largest processes:' + (Describe-Processes (Get-Process)) + | ||
| 'Stopped test processes:' + (Describe-Processes $tested) | ||
| $report | Add-Content -LiteralPath $env:WATCHDOG_REPORT | ||
| $report | Write-Host | ||
| $tested | Stop-Process -Force -ErrorAction SilentlyContinue | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows, if the parity step finishes while the watchdog is sleeping or collecting process details, removing the sentinel does not stop its current iteration:
windows_process_watchdog.ps1checks the sentinel only before its five-second sleep. This cleanup immediately reads the report and deletes its directory without waiting for PowerShell, so an in-flight watchdog action can be missed and the step can return success despite stopping processes. The watchdog can also continue into subsequent CI steps. Save the background PID and wait for it to finish after removing the sentinel, before inspecting the report or deleting its directory. This also satisfies the scoped process-ownership requirement.AGENTS.md reference: rewatch-ocaml/AGENTS.md:L29-L31
Useful? React with 👍 / 👎.