Skip to content

Close connection when TimeoutConnection wrapping fails#743

Merged
zakird merged 3 commits into
zmap:masterfrom
Seanstoppable:ssmith/fix-conn-leak
Jun 28, 2026
Merged

Close connection when TimeoutConnection wrapping fails#743
zakird merged 3 commits into
zmap:masterfrom
Seanstoppable:ssmith/fix-conn-leak

Conversation

@Seanstoppable

Copy link
Copy Markdown
Contributor

This PR was generated with the assistance of GitHub Copilot CLI and may require human review.

Problem

In Dialer.DialContext (conn.go), if NewTimeoutConnection returns an error after the underlying connection has already been established, the function returns the error without closing the connection — leaking the established socket.

Fix

Close the connection on the error path before returning.

ret, err := NewTimeoutConnection(ctx, conn, ...)
if err != nil {
    _ = conn.Close() // avoid leaking the established connection
    return nil, err
}

Severity: low. Found via AI code review.

If NewTimeoutConnection returns an error after the underlying connection
has been established, the connection was returned unclosed, leaking the
established socket. Close it on the error path before returning.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Seanstoppable Seanstoppable marked this pull request as ready for review June 22, 2026 19:39
@zakird zakird enabled auto-merge (squash) June 28, 2026 01:27
@zakird zakird merged commit 83c67f1 into zmap:master Jun 28, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants