Skip to content

fix: close HijackedResponse in attach() to prevent connection leak#6117

Open
SebTardif wants to merge 1 commit into
nektos:masterfrom
SebTardif:fix/close-hijacked-response-attach
Open

fix: close HijackedResponse in attach() to prevent connection leak#6117
SebTardif wants to merge 1 commit into
nektos:masterfrom
SebTardif:fix/close-hijacked-response-attach

Conversation

@SebTardif

Copy link
Copy Markdown

The attach() method creates a HijackedResponse via ContainerAttach but never closes it. The goroutine reading from out.Reader keeps the underlying TCP connection open even after the read completes with EOF.

The sibling exec() method in the same file correctly uses defer resp.Close() for the same resource type (line 600).

This adds defer out.Close() inside the reader goroutine so the connection is released after the container output stream ends. The placement inside the goroutine (rather than at function level) is intentional: attach() returns immediately after spawning the goroutine, so a function-level defer would close the connection prematurely.

This leak has been present since commit 532af98 (2020-02-06).

The attach() method creates a HijackedResponse via ContainerAttach but
never closes it. The goroutine reading from out.Reader keeps the
underlying TCP connection open even after the read completes.

The sibling exec() method at line 600 in the same file correctly uses
defer resp.Close() for the same resource type.

Add defer out.Close() inside the goroutine so the connection is released
after the container output stream ends.

This bug has been present since commit 532af98 (2020-02-06).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant