Cancel the SIGWINCH forwarding task when a build ends#1909
Open
anxkhn wants to merge 1 commit into
Open
Conversation
In Builder.build, the SIGWINCH watcher was launched as a bare, unstructured Task that returned Void and was never stored or cancelled. This caused three problems, all in the task's lifecycle and error handling: - Dropped errors: because the task returned Void, every `try` inside it silently discarded its error. A single throw from `terminal.size` tore down the whole resize loop, so terminal-resize forwarding stopped for the rest of the build with no diagnostic. - Leaked handler and task: the fire-and-forget task kept a process-wide AsyncSignalHandler registered and stayed parked in `for await` after build returned, so in a long-lived invocation both outlived the build. - Use-after-finish: build finishes the request stream in a `defer`, but the still-live task could yield to the finished continuation on the next resize. Extract the forwarding loop into forwardTerminalResize, which logs read/send errors instead of dropping them (mirroring ProcessIO.handleProcess) so a transient failure no longer stops forwarding. Store the task and its signal handler, and tear both down alongside the continuation finish so the watcher does not outlive the build. Add unit tests that cover the recovery-after-error and stream-finish paths. Signed-off-by: Anas Khan <83116240+anxkhn@users.noreply.github.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.
Files changed (2, both intended; no unrelated edits)
Sources/ContainerBuild/Builder.swift(+70/-29): extractforwardTerminalResize(log-not-drop errors);
buildcreates theAsyncSignalHandlereagerly only when aterminal is set, stores the watcher
Task, and cancels handler+task in the existingdefernext tocontinuation.finish().Tests/ContainerBuildTests/BuilderResizeForwardingTests.swift(new, 131 lines):the two regression tests + a minimal collecting
LogHandler.Where to open the PR
apple/containermain. Head: forkanxkhn/containerbranchpatch-4.cryptographically signed (GPG/SSH) per apple/containerization CONTRIBUTING (this is
signing, NOT DCO
-s); the local implement commit is unsigned, so signing is appliedwhen the commit is created/amended at ship.