Repository navigation
fix: stop pipe and console readers at end of file (CPU spin after builder VM) - #24
Merged
Merged
Conversation
…lder VM) A handle at end of file stays readable and availableData returns empty data each time, so a readabilityHandler that only skips empty chunks is called in a tight loop. SerialExpect never removed its handler, so after every builder VM run (disk shrink, image build, machine base build) DockZ spun on the closed console: seen at ~75% of a core for 5 hours, sampled in NSFileHandle fd_monitoring -> availableData -> read. FileHandle.readChunks(_:onEnd:) is now the one way to read asynchronously: it removes its handler at end of file. SerialExpect, the SSH stderr collector, compose output and machine provisioning use it (the last two only stopped when their process exited). Tests: the reader delivers all data and removes itself at EOF; no source file installs a handler by hand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & why
DockZ kept a CPU core busy (~75% for 5 hours, Activity Monitor showed 92%) after the disk shrink. A 3 s
sampleshowed theNSFileHandle.fd_monitoringthread loopingavailableData→read→ empty: a handle at end of file stays readable, andSerialExpect(builder VM console reader) never removed its handler, so it spun after the builder VM powered off. Same class in compose output and machine provisioning (stopped only when their process exited).FileHandle.readChunks(_:onEnd:)is now the single async reader; it removes its handler at EOF. All four call sites use it.Checklist
swift run -c release DockzApp testpasses locally (441 checks)test-runner.swiftHow I verified it
readabilityHandlerby hand again.ps222 CPU-minutes in 5 h;samplestack as above; process started 18:55, builder VM (disk shrink) ran inside it at 19:10. Binary is stripped, so the frames are not symbolised — attribution toSerialExpectis by mechanism and timing.🤖 Generated with Claude Code