diff --git a/CHANGELOG.md b/CHANGELOG.md index 34785ddd6..5ad23b25e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,13 +12,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **`BEADS_DOLT_POOL_READ_TIMEOUT` / `dolt.pool-read-timeout` (and the write twins) now apply to every `bd` command in server mode.** The knobs shipped in #5089, but their env/config ladder ran only for callers of `NewFromConfig*`; - the CLI's own store open and `bd serve`'s provider hand-build their config - and go straight to `New`, so every `bd` command kept the built-in 10 s pool + the CLI's own store open hand-builds its config and goes straight to `New`, + so every `bd` command kept the built-in 10 s pool deadline whatever the knob said — on a large shared server that is what made `bd close` of a bead with dependents die in its recompute with `i/o timeout` and no relief valve. The ladder now runs from the constructor every DoltStore - open shares — the CLI's store, `bd serve`'s store provider and library - callers of `New`/`NewFromConfig*`; `bd serve`'s HTTP data path builds its own + open shares — the CLI's store and library callers of + `New`/`NewFromConfig*`; `bd serve`'s HTTP data path builds its own DSN without pool deadlines and is unchanged ([#6144](https://github.com/gastownhall/beads/issues/6144)). Note for operators of loaded servers: the documented precedence now reaches `bd diff --git a/internal/storage/dolt/BUILD.bazel b/internal/storage/dolt/BUILD.bazel index 2ed025fc3..6459d973c 100644 --- a/internal/storage/dolt/BUILD.bazel +++ b/internal/storage/dolt/BUILD.bazel @@ -268,6 +268,7 @@ go_test( "mixed_table_lifecycle_test.go", "multistore_multiprocess_test.go", "open_test.go", + "pool_timeouts_test.go", "port_provenance_test.go", "portsource_propagation_test.go", "post_migration_pool_heal_integration_test.go", diff --git a/internal/storage/dolt/open.go b/internal/storage/dolt/open.go index 8fd797dc5..9875ae22d 100644 --- a/internal/storage/dolt/open.go +++ b/internal/storage/dolt/open.go @@ -315,7 +315,7 @@ func applyResolvedConfig(ctx context.Context, beadsDir string, fileCfg *configfi cfg.ServerTLS = fileCfg.GetDoltServerTLS() } - // config.yaml rung shared by the pool knobs below. It needs both reads: + // config.yaml rung for the pool-size knob below. It needs both reads: // config.GetString reads a package-global viper populated only by // cmd/bd's config.Initialize(), so for a library consumer it always // returns "" and the project's configured values were silently ignored. @@ -323,7 +323,9 @@ func applyResolvedConfig(ctx context.Context, beadsDir string, fileCfg *configfi // fallback dolt.auto-start carries above for this exact hole. The // fallback follows GetStringFromDir's ladder, so when beadsDir is not // the process CWD a user-level ~/.config/bd/config.yaml value outranks - // that project's file — same behavior as dolt.auto-start. + // that project's file — same behavior as dolt.auto-start. The pool + // deadlines carry the same rung in poolTimeoutFromConfig, which runs + // from applyPoolTimeouts so every DoltStore open gets it. poolCfg := func(key string) string { if v := config.GetString(key); v != "" { return v @@ -359,8 +361,8 @@ func applyResolvedConfig(ctx context.Context, beadsDir string, fileCfg *configfi // overloaded shared-server deployments raise it so ordinary queries stop dying // with "i/o timeout" under load (bd-vz0y9). It is idempotent, and it runs from // New (applyConfigDefaults) so every DoltStore open honors the knob — the CLI's own -// store open and bd serve's provider hand-build their Config and never pass -// through applyResolvedConfig, which is how the knob shipped in #5089 stayed +// store open hand-builds its Config and never passes through +// applyResolvedConfig, which is how the knob shipped in #5089 stayed // inert for every bd command in server mode (gastownhall/beads#6144). func applyPoolTimeouts(cfg *Config) { if cfg.PoolReadTimeout == 0 { diff --git a/internal/storage/dolt/pool_timeouts_test.go b/internal/storage/dolt/pool_timeouts_test.go index e8b7f1692..660d2d131 100644 --- a/internal/storage/dolt/pool_timeouts_test.go +++ b/internal/storage/dolt/pool_timeouts_test.go @@ -1,17 +1,20 @@ package dolt import ( - "github.com/steveyegge/beads/internal/config" + "os" + "path/filepath" "strings" "testing" "time" + + "github.com/steveyegge/beads/internal/config" ) // TestApplyConfigDefaultsAppliesPoolTimeoutLadder pins the pool-deadline knobs // at the seam every DoltStore open shares. applyResolvedConfig applied the // BEADS_DOLT_POOL_READ_TIMEOUT / dolt.pool-read-timeout ladder (#5089), but -// only callers of NewFromConfig* pass through it: the CLI's own store open and -// bd serve's provider hand-build their Config and go straight to New → +// only callers of NewFromConfig* pass through it: the CLI's own store open +// hand-builds its Config and goes straight to New → // applyConfigDefaults, so every `bd` command in server mode kept the built-in // 10s deadline whatever the knob said (gastownhall/beads#6144). New is the one // constructor all of them call, so the ladder has to hold there. @@ -61,4 +64,41 @@ func TestApplyConfigDefaultsAppliesPoolTimeoutLadder(t *testing.T) { t.Fatalf("buildServerDSN default deadline missing: %s", dsn) } }) + + // The config.yaml rung, on the constructor path. The subtests above only + // reach the env rung, so poolTimeoutFromConfig's dir fallback -- the rung a + // library consumer that never called config.Initialize depends on -- was + // pinned only for applyResolvedConfig (TestApplyResolvedConfig in + // open_test.go). This mirrors that subtest through applyConfigDefaults, + // which reads the directory off cfg.BeadsDir rather than a parameter. + t.Run("config.yaml populates the pool deadlines on the constructor path", func(t *testing.T) { + // Premise, as in the base subtest: with a populated global viper the + // dir-fallback rung under test is not the one answering and this would + // pass vacuously. + config.ResetForTesting() + t.Cleanup(config.ResetForTesting) + if config.GetString("dolt.pool-read-timeout") != "" || config.GetString("dolt.pool-write-timeout") != "" { + t.Fatal("global viper unexpectedly configured; this subtest's premise is broken") + } + t.Setenv("BEADS_DOLT_POOL_READ_TIMEOUT", "") + t.Setenv("BEADS_DOLT_POOL_WRITE_TIMEOUT", "") + beadsDir := t.TempDir() + body := "dolt:\n pool-read-timeout: 120s\n pool-write-timeout: 45\n" + if err := os.WriteFile(filepath.Join(beadsDir, "config.yaml"), []byte(body), 0o644); err != nil { + t.Fatalf("writing config.yaml: %v", err) + } + cfg := &Config{ServerMode: true, Database: "ladder", Path: t.TempDir(), BeadsDir: beadsDir} + + applyConfigDefaults(cfg) + + if cfg.PoolReadTimeout != 120*time.Second { + t.Fatalf("PoolReadTimeout = %v, want 120s from config.yaml", cfg.PoolReadTimeout) + } + if cfg.PoolWriteTimeout != 45*time.Second { + t.Fatalf("PoolWriteTimeout = %v, want 45s from config.yaml (bare number = seconds)", cfg.PoolWriteTimeout) + } + if dsn := buildServerDSN(cfg, cfg.Database); !strings.Contains(dsn, "readTimeout=2m0s") { + t.Fatalf("buildServerDSN did not carry the config.yaml deadline: %s", dsn) + } + }) }