Skip to content

fix(upstream): prevent logging after context cancellation in Docker recovery retry - #124

Merged
Dumbris merged 1 commit into
mainfrom
fix/docker-recovery-retry-logging-leak
Nov 3, 2025
Merged

Dumbris merged 1 commit into
mainfrom
fix/docker-recovery-retry-logging-leak

Conversation

@Dumbris

@Dumbris Dumbris commented Nov 3, 2025

Copy link
Copy Markdown
Member

Summary

Fixed another goroutine leak where Docker recovery retry logging occurred after test completion. This is the THIRD location that needed fixing in the Docker recovery monitor.

Root Cause

The issue occurred in handleDockerUnavailable when:

  1. Timer fires (after 2-5 seconds wait)
  2. checkDockerAvailability is called and returns an error
  3. Test completes and context is cancelled
  4. Goroutine logs "Docker recovery retry" without checking if context was cancelled

Error Message

panic: Log in goroutine after TestUpdateListenAddressValidation has completed: 
2025-11-03T19:09:06.504Z	INFO	Docker recovery retry	
{"attempt": 1, "elapsed": "2.001453042s", "next_retry_in": "5s", 
 "error": "docker unavailable: exec: \"docker\": executable file not found in $PATH"}

goroutine 104 [running]:
mcpproxy-go/internal/upstream.(*Manager).handleDockerUnavailable(0xc000122160, {0x10348fe98, 0xc00034c050})
	/Users/runner/work/mcpproxy-go/mcpproxy-go/internal/upstream/manager.go:1896 +0x920

Changes

File: internal/upstream/manager.go

Added context check before "Docker recovery retry" logging (line 1895-1900):

  • Check if recoveryCtx was cancelled before logging
  • Return immediately if shutdown is in progress
  • Prevents goroutine from logging after test cleanup

Complete Fix Summary

This PR completes the Docker recovery monitor fix by addressing ALL logging locations:

PR Location Issue
#122 handleDockerUnavailable after timer Logs without context check after sleep
#123 startDockerRecoveryMonitor initial check Logs on startup without context check
#124 (this PR) handleDockerUnavailable retry logging Logs after failed check without context check

Test Results

✅ Tests pass locally with the fix applied:

go test -v -race -run TestUpdateListenAddressValidation ./internal/runtime/...

Fixes

macOS E2E test failure:

Related PRs

🤖 Generated with Claude Code

…ecovery retry

Fixed another goroutine leak where Docker recovery retry logging occurred
after test completion, causing panic: "Log in goroutine after test has
completed".

The issue occurred in handleDockerUnavailable when:
1. Timer fires and checkDockerAvailability is called
2. Docker check fails (returns error)
3. Test completes and context is cancelled
4. Goroutine logs "Docker recovery retry" without checking context

This completes the fix for Docker recovery monitor logging issues by
adding context checks before ALL logging statements.

Changes:
- Add context check before "Docker recovery retry" log (line 1896)
- Ensures goroutine exits cleanly if context was cancelled during check

Fixes test failures:
- End-to-End Tests (macos-latest, 1.23.10)
  https://github.com/smart-mcp-proxy/mcpproxy-go/actions/runs/19046210469

Complements PR #122 and PR #123.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@github-actions

github-actions Bot commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

📦 Build Artifacts for PR #124

Version: v0.9.24-dev-9d7b6e3-pr124
Latest tag: v0.9.24

Available Artifacts

  • frontend-dist-pr (177 KB)
  • archive-linux-arm64 (8.8 MB)
  • archive-linux-amd64 (9.7 MB)
  • archive-darwin-arm64 (16 MB)
  • archive-windows-amd64 (18 MB)
  • installer-dmg-darwin-arm64 (18 MB)
  • archive-windows-arm64 (16 MB)
  • archive-darwin-amd64 (18 MB)
  • installer-dmg-darwin-amd64 (20 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 19046495226 --repo smart-mcp-proxy/mcpproxy-go

# Or download a specific artifact:
gh run download 19046495226 --name dmg-darwin-arm64

Note: Artifacts expire in 14 days.

@Dumbris
Dumbris merged commit f30ae25 into main Nov 3, 2025
@Dumbris
Dumbris deleted the fix/docker-recovery-retry-logging-leak branch November 3, 2025 19:23
Dumbris added a commit that referenced this pull request Nov 3, 2025
…ellation

Fixed OAuth event monitor goroutine leak where logging occurred after test
completion, causing panic: "Log in goroutine after test has completed".

The issue occurred in startOAuthEventMonitor when:
1. Ticker fires (every 5 seconds)
2. processOAuthEvents() is called
3. Test completes and context is cancelled
4. processOAuthEvents() logs debug message without checking context

This is similar to the Docker recovery monitor issues fixed in PR #122, #123, #124.

Changes:
- Add context check after ticker fires, before calling processOAuthEvents()
- Return immediately if context was cancelled during ticker wait
- Prevents goroutine from logging after test cleanup

Fixes test failures:
- Unit Tests (windows-latest, 1.23.10)
  https://github.com/smart-mcp-proxy/mcpproxy-go/actions/runs/19046681617/job/54396553672

Error:
```
panic: Log in goroutine after TestUpdateListenAddressValidation has completed:
2025-11-03T19:28:45.714Z	DEBUG	processOAuthEvents: checking for OAuth completion events...

goroutine 144 [running]:
mcpproxy-go/internal/upstream.(*Manager).processOAuthEvents(0xc0006b64d0)
	D:/a/mcpproxy-go/mcpproxy-go/internal/upstream/manager.go:1493 +0x9e
mcpproxy-go/internal/upstream.(*Manager).startOAuthEventMonitor(0xc0006b64d0, {0x1414d55f8, 0xc000600a50})
	D:/a/mcpproxy-go/mcpproxy-go/internal/upstream/manager.go:1474 +0x1e8
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Dumbris added a commit that referenced this pull request Nov 3, 2025
…covery

Fixed a race condition where Docker recovery retry logging occurred after
test completion despite having a context check. The issue was using the
child `recoveryCtx` instead of parent `ctx` for shutdown detection.

Root Cause:
- Child context (`recoveryCtx`) cancellation may lag behind parent (`ctx`)
- Test cleanup cancels parent context immediately
- Tiny window between context check and log execution
- On CI machines, this race is more likely due to scheduling delays

Changes:
- Check parent `ctx.Done()` instead of `recoveryCtx.Done()` (line 1905)
- Parent context reflects shutdown state more immediately
- Eliminates race window between check and log execution

This completes the fix from PR #124 by using the correct context for
shutdown detection.

Fixes:
- Unit Tests (macos-latest, 1.23.10) on main branch
- Race condition: "Log in goroutine after test has completed"

Error:
```
panic: Log in goroutine after TestUpdateListenAddressValidation has completed:
2025-11-03T20:02:22.176Z	INFO	Docker recovery retry
{"attempt": 1, "elapsed": "2.002340625s", "next_retry_in": "5s"}

mcpproxy-go/internal/upstream.(*Manager).handleDockerUnavailable
	internal/upstream/manager.go:1910
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
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.

1 participant