Skip to content

[bug] Duplicate close call in newListener cleanup #2111

@docker-agent

Description

@docker-agent

🟠 high - bug

File: cmd/root/flags.go (line 162)

Code

stop := context.AfterFunc(ctx, func() {
		_ = ln.Close()
	})
	cleanup := func() {
		stop()
		_ = ln.Close()
	}
	return ln, cleanup, nil

Problem

The ln.Close() is called twice in the cleanup function. Once directly as _ = ln.Close() and again via stop(), which also calls _ = ln.Close(). This redundant call might not cause an immediate error because net.Listener.Close() is often idempotent, but it's unnecessary and can be a sign of a logic error.

Suggested Fix

Remove the redundant _ = ln.Close() call from the cleanup function. The stop() function already handles closing the listener.


Found by nightly codebase scan

Metadata

Metadata

Assignees

No one assigned

    Labels

    automatedIssues created by cagentkind/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions