Skip to content

Fix panic when Docker is unresponsive (Issue #312)#381

Open
aviralgarg05 wants to merge 2 commits intodocker:mainfrom
aviralgarg05:fix/issue-312-docker-panic
Open

Fix panic when Docker is unresponsive (Issue #312)#381
aviralgarg05 wants to merge 2 commits intodocker:mainfrom
aviralgarg05:fix/issue-312-docker-panic

Conversation

@aviralgarg05
Copy link

Related issue
Fixes #312

What I did
When Docker Desktop is unresponsive (e.g., paused or exhausted resources), the internal apiClient() wrapper in pkg/docker returns nil. Previously, the code did not check for this, leading to a nil pointer dereference panic when tools like mcp-add or mcp-find attempted to interact with Docker.

This PR introduces a safe client() helper method in pkg/docker/client.go that checks if the API client is nil and returns a descriptive error ("docker client is not available") instead of panicking.

I have updated all files in pkg/docker (containers.go, images.go, network.go, volumes.go) to use this safe helper.

I also added a regression test TestClientSafeError in pkg/docker/client_test.go that simulates a nil client and verifies that:

  1. The application does not panic.
  2. The correct error message is returned.

Verification

  • Run go test -v ./pkg/docker/... to verify the fix and ensure no regressions.
  • Manual verification: The gateway should now return a graceful error message to the client instead of crashing if Docker is unavailable.

(not mandatory) A picture of a cute animal
Cute Animal

@aviralgarg05 aviralgarg05 requested a review from a team as a code owner February 4, 2026 08:10
Copy link
Contributor

@Pnkcaht Pnkcaht left a comment

Choose a reason for hiding this comment

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

Almost perfect, but with a critical bug in ImageExists: it uses the ContainerInspect API instead of ImageInspect, which I think is wrong (containers ≠ images)

Copy link
Contributor

@Pnkcaht Pnkcaht left a comment

Choose a reason for hiding this comment

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

I don't yet have permission to actually approve and merge it, but I believe the fix you implemented will go straight to the merge by the team. Anyway, LGTM for me, good pull request

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 Report: MCP Gateway Panic on mcp-add When Docker is Unresponsive

2 participants