Skip to content

fix: remove stale instance entry on recreate and guard stop against missing containers#468

Open
Syedowais312 wants to merge 4 commits into
microcks:masterfrom
Syedowais312:fix/stale-instance-cleanup
Open

fix: remove stale instance entry on recreate and guard stop against missing containers#468
Syedowais312 wants to merge 4 commits into
microcks:masterfrom
Syedowais312:fix/stale-instance-cleanup

Conversation

@Syedowais312

@Syedowais312 Syedowais312 commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Problem

When a container is removed externally (e.g. docker system prune) and
microcks start recreates it, the old instance entry was never removed from
config causing duplicate instance records to accumulate on every recreate.

Two root causes:

  1. RemoveInstance matched by Name (not unique) instead of ContainerID (unique)
  2. The autoRemove path in stop.go was passing instance.Name to RemoveInstance,
    silently failing to remove the correct entry
  3. start.go was clearing instance.ContainerID = "" instead of calling
    RemoveInstance to actually remove the stale record from config

Changes

  • cmd/start.go: call localConfig.RemoveInstance(instance.ContainerID) to
    remove the stale record before recreating, instead of just clearing the local variable
  • cmd/stop.go: pass instance.ContainerID to RemoveInstance in the autoRemove path
  • pkg/config/localconfig.go: RemoveInstance now matches by ContainerID instead of Name

Testing

Ran docker rm <container> while config shows status: Running, then
microcks start --name <instance> config shows a single clean entry with
the new container ID, no duplicates.

Realted: #456

Fix: #483

…issing containers

Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
@Vaishnav88sk

Copy link
Copy Markdown

Matching by ContainerID instead of Name is the correct approach. Could you add a test case for the duplicate-entry scenario?

Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
@Syedowais312

Copy link
Copy Markdown
Contributor Author

Matching by ContainerID instead of Name is the correct approach. Could you add a test case for the duplicate-entry scenario?

i have added appropriate test cases in pkg/config/localconfig_test.go

@Vaishnav88sk

Copy link
Copy Markdown

Thanks for adding tests after the earlier review feedback.

One thing I want to call out: the PR title mentions “guard stop against missing containers”, but I don’t see an actual missing-container guard added in stop.go in this diff. So:

  • add the missing guard behavior as well.

@Syedowais312 Syedowais312 changed the title fix: remove stale instance entry on recreate and guard stop against m… fix: remove stale instance entry on recreate and guard stop against missing containers Jul 16, 2026
@Syedowais312
Syedowais312 force-pushed the fix/stale-instance-cleanup branch from a859375 to 700e6db Compare July 16, 2026 17:58
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
@Syedowais312

Copy link
Copy Markdown
Contributor Author

Thanks for adding tests after the earlier review feedback.

One thing I want to call out: the PR title mentions “guard stop against missing containers”, but I don’t see an actual missing-container guard added in stop.go in this diff. So:

sorry i missed it earlier.
i have added a checks to verify whether the container still exists before trying to stop it.

Comment thread pkg/config/localconfig_test.go
Signed-off-by: syedowais312 <syedowais312sf@gmail.com>
@Syedowais312
Syedowais312 force-pushed the fix/stale-instance-cleanup branch from 060992b to 6a740ad Compare July 24, 2026 16:52

@Vaishnav88sk Vaishnav88sk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please resolve that. After that LGTM. 👍🏻

Comment thread cmd/stop.go
Comment on lines +43 to +44
exists, _ := containerClient.ContainerExists(instance.ContainerID)
errors.CheckError(err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a bug here: ContainerExists(...) returns (bool, error), but the error is being discarded with _, and then errors.CheckError(err) is checking the previous err value instead.

Please capture the returned error here and validate that one.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also line ~70,
This should stay as RemoveInstance(instance.ContainerID), not RemoveInstance(instance.Name).

Switching it back to instance.Name reintroduces the original issue this PR is fixing, since RemoveInstance() was changed to match by ContainerID.

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.

bug: stale instance entries accumulate in config when container is recreated

2 participants