fix(sync): guard db sync against a stopped local DB container - #112
Merged
Conversation
sync --db built and ran the remote-dump/local-import (or reverse) docker exec pipeline without ever checking the local DB container was running, unlike db import --stream-db and db dump/import -f, which already guard this via ensureLocalDBRunning. Against a stopped/missing container, docker exec can behave unpredictably (including hanging indefinitely) instead of failing fast with a clear error. Root-caused via a SIGQUIT goroutine dump showing the main goroutine blocked in importCmd.Wait() (db.go:1113) after the remote dump had already finished - confirmed by the user: running `govard env up` first made the exact same sync --db command work. Add the same ensureLocalDBRunning guard at the start of each sync direction's action closure, right before touching docker exec. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sync --db(both directions) built and ran the docker exec dump/importpipeline against the local DB container without ever checking it was
running, unlike
db import --stream-db/db dump/db import -f, whichalready guard this via
ensureLocalDBRunning.docker execcan behaveunpredictably instead of failing fast - in the reported case, the whole
sync --dbcommand hung indefinitely with no error.SIGQUITgoroutine dump of the stuck process: the maingoroutine was blocked in
importCmd.Wait()(db.go:1113) after the remotedump had already finished - so the remote/SSH side was never the problem.
Confirmed with the reporting user: running
govard env upfirst (bringingthe local container up) made the exact same
sync --dbcommand succeed.ensureLocalDBRunningguard to both sync-direction actionclosures in
buildDatabaseSyncAction, right before the docker exec commandis built/run - so a stopped container now fails immediately with
database container <name> is not runninginstead of hanging.Closes #111
Test plan
TestSyncPlanDatabaseActionFailsFastWhenLocalContainerNotRunning(
tests/sync_plan_test.go) - runs the actual returned DB action closureagainst a hermetic test environment with no real container, asserting
it fails fast with a clear "is not running" error instead of hanging
TestSyncPlanScopes/TestSyncPlanDatabaseStopsWhenRemoteCredentialsCannotBeResolvedstill pass (the guard lives inside the action closure, not at plan-build
time, so hermetic plan-building tests are unaffected)
go build ./...,go vet ./...,go test ./...all passgofmt -s -l .shows no drift on changed files