From 98e39f019badfb79996bd36e8b73faea8e793371 Mon Sep 17 00:00:00 2001 From: Ashish Sharda Date: Mon, 23 Mar 2026 19:40:08 -0400 Subject: [PATCH] [scd] Fix missing transaction timeout in SCD datastore Apply context.WithTimeout in SCD Transact() so database transactions are bounded by DefaultTimeout (10s), preventing the DSS from continuing to process requests after the HTTP layer has already timed out. RID and AUX datastores already applied this pattern; SCD was missing it, causing the observed behaviour in #1393 where a PUT /dss/v1/operational_intent_references request completed and committed state changes even after the client received a 503 timeout. Co-Authored-By: Ashish Sharda --- pkg/scd/store/datastore/store.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/scd/store/datastore/store.go b/pkg/scd/store/datastore/store.go index a9fa230b4..afec45bb0 100644 --- a/pkg/scd/store/datastore/store.go +++ b/pkg/scd/store/datastore/store.go @@ -2,6 +2,7 @@ package datastore import ( "context" + "time" "github.com/cockroachdb/cockroach-go/v2/crdb" crdbpgx "github.com/cockroachdb/cockroach-go/v2/crdb/crdbpgxv5" @@ -25,6 +26,11 @@ var ( // DefaultClock is what is used as the Store's clock, returned from Dial. DefaultClock = clockwork.NewRealClock() + // DefaultTimeout is the timeout applied to the txn retrier. + // If a given deadline is already supplied on the context, the earlier + // deadline is used. + DefaultTimeout = 10 * time.Second + // DatabaseName is the name of database storing strategic conflict detection data. DatabaseName = "scd" ) @@ -92,6 +98,9 @@ func (s *Store) Interact(_ context.Context) (repos.Repository, error) { // Transact implements store.Transactor interface. func (s *Store) Transact(ctx context.Context, f func(context.Context, repos.Repository) error) error { + ctx, cancel := context.WithTimeout(ctx, DefaultTimeout) + defer cancel() + ctx = crdb.WithMaxRetries(ctx, flags.ConnectParameters().MaxRetries) return crdbpgx.ExecuteTx(ctx, s.db.Pool, pgx.TxOptions{IsoLevel: pgx.Serializable}, func(tx pgx.Tx) error { return f(ctx, &repo{