Skip to content

Conversation

@Nepomuk5665
Copy link
Contributor

Summary

  • Add nil check for inspected.State before accessing inspected.State.Running in the Remove function
  • Prevents potential panic if Docker returns a container without State information

Problem

In pkg/compose/remove.go:67, the code accesses inspected.State.Running without first checking if inspected.State is nil:

if !inspected.State.Running || (options.Stop && s.dryRun) {

While Docker containers typically always have State populated, this is inconsistent with nil checks done elsewhere in the codebase and could cause a panic in edge cases (race conditions, unusual Docker states, or API changes).

Solution

Add a nil check consistent with the pattern used elsewhere in the codebase:

  • pkg/compose/convergence.go:836 - ctr.State != nil && ctr.State.Status
  • pkg/compose/convergence.go:862 - ctr.State != nil && ctr.State.Status
  • pkg/compose/monitor.go:150 - inspect.State != nil && (inspect.State.Restarting || ...)
  • pkg/compose/ps.go:70 - if inspect.State != nil {

The fix adds a nil check that treats containers with nil State as "stopped" (which is the safe default for the Remove operation).

@Nepomuk5665 Nepomuk5665 requested a review from a team as a code owner January 26, 2026 08:57
@Nepomuk5665 Nepomuk5665 requested review from glours and ndeloof January 26, 2026 08:57
…n Remove

Add nil check for inspected.State before accessing inspected.State.Running
in the Remove function. This is consistent with nil checks done elsewhere
in the codebase (convergence.go, monitor.go, ps.go) and prevents a potential
panic if Docker returns a container without State information.

Signed-off-by: Nepomuk Crhonek <105591323+Nepomuk5665@users.noreply.github.com>
@Nepomuk5665 Nepomuk5665 force-pushed the fix-nil-state-check-in-remove branch from fc08ec9 to 46936f6 Compare January 26, 2026 08:57
@ndeloof ndeloof enabled auto-merge (rebase) January 26, 2026 09:06
@ndeloof
Copy link
Contributor

ndeloof commented Jan 26, 2026

add nolint:gogyclo on this function, we can look into refactoring to make code simpler in a follow-up PR

@codecov
Copy link

codecov bot commented Jan 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

3 participants