Skip to content

[bug] Ignored error on localRt.Close() #1800

@docker-agent

Description

@docker-agent

🟡 medium - bug

File: cmd/root/run.go (line 236)

Code

defer func() {
	if err := rt.Close(); err != nil {
		slog.Error("Failed to close runtime", "error", err)
	}
}()

Problem

In the runOrExec function, there's a defer call to rt.Close() which logs an error if it occurs. However, this is for the initial local runtime. When new sessions are spawned via createSessionSpawner, each new localRt also needs to be closed. The cleanup function in createSessionSpawner only calls team.StopToolSets, but not localRt.Close(). This could lead to resource leaks if the localRt in spawned sessions holds open resources.

Suggested Fix

Modify the cleanup function within createSessionSpawner to also close the localRt that it creates. For example:

cleanup := func() {
	cleanupCtx := context.WithoutCancel(spawnCtx)
	if err := team.StopToolSets(cleanupCtx); err != nil {
		slog.Error("Failed to stop tool sets during cleanup", "error", err)
	}
	if err := localRt.Close(); err != nil {
		slog.Error("Failed to close runtime during spawned session cleanup", "error", err)
	}
}

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