fix: applyConfigDefaults uses full port resolution chain#2591
fix: applyConfigDefaults uses full port resolution chain#2591steveyegge merged 2 commits intosteveyegge:mainfrom
Conversation
When no BEADS_DOLT_SERVER_PORT env var is set, applyConfigDefaults() left cfg.ServerPort at 0, which the MySQL driver defaulted to 3307. If another project's Dolt was on 3307, bd connected to the wrong database — causing PROJECT IDENTITY MISMATCH errors. Now falls back to doltserver.DefaultConfig() which checks: port file > config.yaml > metadata.json > ephemeral. Fixes steveyegge#2590 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
ktoulgaridis
left a comment
There was a problem hiding this comment.
All non-Embedded-Dolt checks pass (9/9). Embedded Dolt failures are systemic across all PRs and main. Clean 6-line fix wiring applyConfigDefaults() into the full port resolution chain (port file > config.yaml > metadata.json). Prevents cross-project connections when no env var is set. LGTM.
|
Thanks for pushing on this. While auditing #2590, I found a remaining CLI case that still fails even when I opened a focused follow-up PR here with a deterministic repro that fails on unpatched Your PR helped narrow the search area, so I wanted to cross-link the remaining case here rather than duplicate discussion. Thanks again for digging into this. |
Summary
applyConfigDefaults()instore.goonly checked env vars (BEADS_DOLT_SERVER_PORT/BEADS_DOLT_PORT) for port resolution. When no env var was set,cfg.ServerPortstayed at 0, and the MySQL driver defaulted to port 3307. If another project's Dolt was running on 3307,bdconnected to the wrong database — causingPROJECT IDENTITY MISMATCHerrors.The fix: when
cfg.ServerPortis still 0 after env var check, calldoltserver.DefaultConfig(cfg.Path)to resolve using the full priority chain (port file > config.yaml > metadata.json > ephemeral). This function already existed and was used byopen.go— it just wasn't wired intoapplyConfigDefaults().Fixes #2590
The bug
Two independent port resolution paths existed:
doltserver.DefaultConfig()doltserver.go:298applyConfigDefaults()store.go:545applyConfigDefaults()is called byNew()(the main store constructor). So everybdcommand that opens a store used the incomplete resolution path.The fix
6 lines added after the env var check in
applyConfigDefaults():Reproduction
Test plan
go build ./...compilesgo test ./internal/storage/dolt/ -run TestApplyConfigDefaults— 5 existing tests passbd listconnects to port file port without env var overridedoltserver.DefaultConfigreads from filesystem)🤖 Generated with Claude Code