Skip to content

fix(cli): warn when sync stops after saving the lock file - #643

Merged
eitsupi merged 7 commits into
mainfrom
fix/review-followups
Dec 4, 2026
Merged

eitsupi merged 7 commits into
mainfrom
fix/review-followups

Conversation

@eitsupi

@eitsupi eitsupi commented Dec 2, 2026

Copy link
Copy Markdown
Member

Follow-ups to the non-blocking review notes on #630, #631, #634 and #635.

dbc sync saves the lock file before installing. It already warned on install failure, but could exit without a warning after Ctrl-C or SIGINT. It now warns once on stderr if it saved the lock file and installation did not finish or could not be confirmed.

On an install error, the warning asks you to fix it and rerun dbc sync. On interruption, it says installation "may be incomplete" and asks you to rerun, since the last install may have finished before sync received its result. Both warnings say the lock file "has been saved" to avoid implying that its contents changed.

SIGINT stops the CLI program without canceling sync's worker context. On exit, sync prevents a preparation worker from starting a lock-file write and waits for any write already in progress before deciding whether to warn.

Smaller follow-ups:

A sync stopped by Ctrl-C or SIGINT after writing the lock file left it
ahead of the installed drivers without a warning. The warning is now
printed once after the program stops, worded for a failed install or a
stop. Once the program has stopped, a worker still preparing no longer
writes the lock file.
@zeroshade

Copy link
Copy Markdown
Member

Looks good to me. No blocking issues, just a few small notes.

Checks run on 2d73e19: go vet ./cmd/dbc/ ./ is clean. With -race -count=3, the new TestLockWriteState* tests, TestSyncStopped* (quit key and interrupt), TestSyncUpgradeInstallFailureKeepsNewLock and TestSyncInstallFailure* all pass in the Env suite. I did not run the full suite.

How the fix holds up

  • Where the warning is printed. It used to go to stderr from inside Update while the program was running. Now it is printed once, after prog.Run() returns, so it can't garble the screen output.
  • Both ways of stopping are covered.
    • Quit key: s.cancel() runs, and resolve checks r.ctx.Err() before writing.
    • SIGINT without a terminal: the worker context isn't canceled. Bubbletea returns ErrInterrupted with the last model, and finish() stops any lock-file write that hasn't started yet. TestSyncStoppedBeforeSavingLockDoesNotWrite/interrupt checks this.
  • Model copies. lockWrite is a pointer, so every copy sees the same state. If Run returns the initial model (bubbletea does this when it fails before or during startup), written stays false and no warning is printed, which is correct.
  • --locked. The old !s.Locked check is no longer needed: resolve returns before write, so written stays false.
  • dbc lock. It builds driverListResolution without a lockWriteState, and write handles a nil state, so nothing changes there.
  • Errors after the lock file is saved. Nothing in resolve can fail after the write, so the "may be incomplete" wording can't show up for a planning error by mistake.
  • The two doc comments are accurate.
    • fetchIndexes gives each configured registry its own pointer (registry := &registries[i]).
    • GetWithConstraint uses Constraints.Check and GreaterThan, which both ignore build metadata.
  • The targetTuple removal only inlines the calls. It compiles, so no callers remain.

Nits

  1. ExitWarning() has a side effect. It calls finish(), which permanently blocks further lock-file writes. Anything that calls it before Run returns, such as a future status line or a test helper, would quietly make sync fail with context.Canceled. The interface comment says "called once after the program stops", but the method itself doesn't say so. A sentence on syncModel.ExitWarning would cover it. Another option is to move finish() into printExitWarning behind a separate interface.
  2. finish() waits for a write in progress. The mutex is held during the write, so Ctrl-C waits for atomicfile.WriteFilePreservingMode to finish. That's needed for a correct answer and is quick on a local disk, but exit could hang on a stuck network filesystem. This seems like an acceptable trade-off; just noting it.
  3. Repeated test setup. The two new suite tests build projectDir and dbc.toml by hand in both places. That makes sense, because writeDriverList always writes to suite.tempdir and the subtests need separate directories. A directory parameter on writeDriverList, or a small helper, would remove the repetition.
  4. The 50 ms wait in TestLockWriteStateFinishWaitsForWrite can only pass by mistake, never fail by mistake, so it won't flake in CI.

@eitsupi

eitsupi commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

Thank you for your review. I've updated the comments.
I'll merge it now.

@eitsupi
eitsupi merged commit 975febe into main Dec 4, 2026
15 checks passed
@eitsupi
eitsupi deleted the fix/review-followups branch December 4, 2026 00:58

This branch was previously deployed

1 inactive deployment
snapshot — 27a7240a Deployed Dec 4, 2026 by eitsupi via snapshot #1474
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.

2 participants