fix(runtime): close ExecNotWait connection, guard NetworkInspect error path#3148
Open
Aprazor wants to merge 1 commit intosrl-labs:mainfrom
Open
fix(runtime): close ExecNotWait connection, guard NetworkInspect error path#3148Aprazor wants to merge 1 commit intosrl-labs:mainfrom
Aprazor wants to merge 1 commit intosrl-labs:mainfrom
Conversation
…r path Three runtime fixes: - runtime/docker/docker.go (ExecNotWait): ContainerExecAttach returns a HijackedResponse holding a TCP connection. The response was discarded with _, leaking a TCP socket on every call. Close it after attach. - runtime/docker/docker.go (WithMgmtNet): after NetworkInspect fails, the code falls through to access netRes.Options on the zero-value response. While Go nil-map reads don't panic, this is accidentally correct. Use else-if to only access the result on success. - runtime/podman/podman.go (CreateContainer): on CreateWithSpec error, the code accessed res.ID in the log and returned it to callers. Check err first and return a wrapped error instead of a potentially invalid container ID.
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.
Summary
Three runtime correctness fixes:
1. TCP connection leak in
ExecNotWait(Docker)ContainerExecAttachreturns atypes.HijackedResponseholding a TCP connection and bufio reader. The normalExec()method properly callsdefer rsp.Close(), butExecNotWaitdiscards the response with_, leaking a TCP socket on every call.Fix: Capture the response and close it after attach.
2.
NetworkInspecterror fallthrough (Docker)In
WithMgmtNet, afterNetworkInspectfails, the code sets MTU to 1500 and logs the error, but falls through to accessnetRes.Optionson the zero-valueNetworkResource. While Go nil-map reads don't panic (returns zero value), this is accidentally correct and fragile.Fix: Use
else ifsonetRes.Optionsis only accessed when inspect succeeded.3.
CreateContaineraccesses result on error (Podman)After
CreateWithSpecfails, the code accessesres.IDandres.Warningsin the log statement and returnsres.IDto callers. This returns a potentially invalid container ID that callers may try to use.Fix: Check error first and return a wrapped error without accessing the result.
Testing
go vet ./runtime/docker/...— cleango test -race ./runtime/docker/...— all pass