Skip to content

[bug] Ignored error from cleanup function #1987

@docker-agent

Description

@docker-agent

🟡 medium - bug

File: cmd/root/api.go (line 70)

Code

if _, recordCleanup, err := setupRecordingProxy(f.recordPath, &f.runConfig); err != nil {
	return err
} else {
	defer func() {
		if err := recordCleanup(); err != nil {
			slog.Error("Failed to cleanup recording proxy", "error", err)
		}
	}()
}

Problem

The recordCleanup() function, which is deferred, returns an error that is not checked or handled when setupRecordingProxy itself returns an error. This means that if setupRecordingProxy fails, the cleanup for a partially set up recording proxy might also fail silently, potentially leaving resources open or in an inconsistent state.

Suggested Fix

The error from recordCleanup() should be checked and handled, especially in the case where setupRecordingProxy already returned an error. It could be added to a slice of errors to be returned at the end of the function.


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