Repository navigation
Conversation
close() now cancels connectionTask and waits on connectionTask.result, ignoring the task’s error, instead of beginGracefulShutdown() followed by connectionTask.value. The connection task still enters the transport, so connect() runs and the preconfigured writer is finished. RPCs still in flight on this client are cancelled rather than drained. VminitdCloseTests drives an unread socket pair through forty immediate closes, one close after several yields, and a second close on the same value. Fixes apple#970
JaewonHur
reviewed
Nov 13, 2026
| @@ -80,8 +80,10 @@ public struct Vminitd: Sendable { | |||
|
|
|||
| /// Close the connection to the guest agent. | |||
| public func close() async throws { | |||
Contributor
There was a problem hiding this comment.
Could you leave comment above it cancels in-flight RPCs?
Author
There was a problem hiding this comment.
Added in 03f6610: the doc comment on close() now says it cancels the connection task rather than shutting down gracefully, so any RPCs still in flight on the agent are cancelled too.
This branch has not been deployed
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.
Motivation
Closing the guest agent before its connection has started aborts the host process with SIGTRAP (exit 133). That happens when a caller cancels an in-flight container request, such as a statistics call, a few milliseconds after it begins. The caller gets a fatal error that an async writer was destroyed without finish(), instead of a cancellation or RPC error.
close() called beginGracefulShutdown() and then awaited the connection task. If that runs before the transport has consumed the preconfigured channel, the client moves from not-started to stopped without notifying the transport, runConnections() throws clientIsStopped, and connect() never runs. The outbound writer is finished only inside connect(), so the last release hits the writer’s deinit precondition. The same unfinished writer is left behind when the client is already running but the wrapped channel is still idle or configuring.
Summary
close() now cancels connectionTask and waits on connectionTask.result, ignoring the task’s error, instead of beginGracefulShutdown() followed by connectionTask.value. The connection task still enters the transport, so connect() runs and the preconfigured writer is finished. RPCs still in flight on this client are cancelled rather than drained. VminitdCloseTests drives an unread socket pair through forty immediate closes, one close after several yields, and a second close on the same value.
How it was tested
The targeted tests for the containerization Vminitd: change pass locally. The tests in
Tests/ContainerizationTests/VminitdCloseTests.swiftfail without the fix in the containerization Vminitd: change (checked by reverting the source changes). The new test Tests/ContainerizationTests/VminitdCloseTests.swift did not run here: no test runner for it was available.Fixes #970
AI was used for assistance.