Skip to content

fix: reclaim idle Docker sandboxes on a schedule - #5878

Open
xixi-box wants to merge 1 commit into
Tencent:mainfrom
xixi-box:fix/issue-5868-032c67f-9b46c737
Open

xixi-box wants to merge 1 commit into
Tencent:mainfrom
xixi-box:fix/issue-5868-032c67f-9b46c737

Conversation

@xixi-box

Copy link
Copy Markdown
Contributor

Fixes #5868

Description

Idle Docker containers could stay alive indefinitely when users stopped sending requests. The idle sweep ran only after a sandbox was created or connected.

Register a separate five-minute Docker idle sweep that finds daemons through saved workspace configs and logs each sweep's start and result. The sweep honors the TTL already stamped by the shared Docker create path for both ordinary and skill-image containers. Older managed containers without a TTL label use the longest configured TTL for their endpoint.

Docker creation now returns a capacity error when the daemon reaches its managed-container limit. The default is 16, configurable through WEKNORA_SANDBOX_DOCKER_MAX_CONTAINERS. Running and stopped containers both count. Each app process serializes creation per daemon address, so simultaneous creates from different replicas can temporarily exceed the threshold.

Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 💥 Breaking change
  • 📚 Documentation update
  • 🎨 Refactor
  • ⚡ Performance improvement
  • 🧪 Test
  • 🔧 Configuration / Build / CI

Related Issue

Fixes #5868

Testing

Tests: go test -count=1 -v ./internal/application/service -run '^TestSkillMaintenanceReclaimsIdleDockerSandboxes$'.
Result: Base: go test ./internal/sandbox/... passed before regressions were added.
Result: Base: go test -count=1 ./internal/application/service -run '^(TestReapStuckRuns|TestReconcileSnapshots|TestPruneSupersededSnapshots|TestTenantSkillServiceStartIsIdempotent)' passed.
Result: Base: go test -count=1 -v ./internal/application/service -run '^TestSkillMaintenanceReclaimsIdleDockerSandboxes$' failed for the expected reason. No expired containers were deleted (OSSCOUT_BASE.log).
Result: Patched: go test -count=1 -v ./internal/application/service -run '^TestSkillMaintenanceReclaimsIdleDockerSandboxes$' passed and logged reclamation of two containers (OSSCOUT_PATCHED.log).
Result: go test -count=1 -v ./internal/sandbox -run '^TestDockerClientCreateEnforcesContainerLimitForSkillImages$' failed on base because creation returned no capacity error and passed on patched code (OSSCOUT_CAPACITY_BASE.log, OSSCOUT_CAPACITY_PATCHED.log).
Result: Patched: go test -count=1 ./internal/sandbox/... passed all four sandbox packages (OSSCOUT_SANDBOX.log).
Result: Patched: go test -race -tags sqlite_fts5 -count=1 ./internal/sandbox/... passed all four sandbox packages (OSSCOUT_RACE.log). The earlier run caught terminal fixture activity refresh after removing the fixture's zero TTL. Restoring that setting resolved the failures.
Result: Patched: go test -tags sqlite_fts5 -count=1 ./internal/application/service passed (OSSCOUT_SERVICE.log).
Result: Patched: go test -tags sqlite_fts5 -count=1 ./internal/handler -run '^(TestSandboxConnectionCheck|TestSandboxCheckReason|TestDeepSandboxCheck|TestRunStatelessSandboxCheck)' passed (OSSCOUT_HANDLER.log).
Result: Patched: go test -tags docker_integration ./internal/sandbox -run '^$' compiled the tagged suite (OSSCOUT_DOCKER_BUILD.log).
Regression coverage: internal/application/service/tenant_skill_reaper_test.go.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests for the changed packages/components pass
  • Diff-scoped lint passes where applicable (for Go: golangci-lint run --new-from-rev=origin/main ./...)
  • Full-repository checks were run, or any unrelated/environment-dependent failures are documented above
  • Self-reviewed the code
  • Added/updated tests covering the change
  • Updated related documentation (README, website-docs/, Swagger annotations, etc.)
  • Breaking changes are clearly called out in the description above

Screenshots / Recordings

Backend-only change.

Signed-off-by: wangshun <96341168+xixi-box@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant