Skip to content

Commit 7750d86

Browse files
Add max_attempts for close slot activity, and specify query mode for slot check (#4148)
- Noticed that for a mirror which fails due to snapshot invalid identifier the final closeSlot activity can hang as it has infinite retries and is run on defer when the session worker is no longer available. Adding max_attempts of 2 here - Noticed this error: ``` error checking for replication slot - <slot_name> : expected 0 arguments, got 1 ``` even though we clearly set $1 for that query. Turns out it can happen with prepared statements to poolers. Specifying query mode at query level like we do in other places
1 parent a0668fc commit 7750d86

2 files changed

Lines changed: 4 additions & 5 deletions

File tree

flow/connectors/postgres/client.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func (c *PostgresConnector) checkSlotAndPublication(ctx context.Context, slot st
249249
var slotName pgtype.Text
250250
err := c.conn.QueryRow(ctx,
251251
"SELECT slot_name FROM pg_replication_slots WHERE slot_name = $1",
252-
slot).Scan(&slotName)
252+
pgx.QueryExecModeSimpleProtocol, slot).Scan(&slotName)
253253
if err != nil {
254254
// check if the error is a "no rows" error
255255
if !errors.Is(err, pgx.ErrNoRows) {
@@ -262,7 +262,7 @@ func (c *PostgresConnector) checkSlotAndPublication(ctx context.Context, slot st
262262
// Check if the publication exists
263263
var pubName pgtype.Text
264264
if err := c.conn.QueryRow(ctx,
265-
"SELECT pubname FROM pg_publication WHERE pubname = $1", publication,
265+
"SELECT pubname FROM pg_publication WHERE pubname = $1", pgx.QueryExecModeSimpleProtocol, publication,
266266
).Scan(&pubName); err != nil {
267267
// check if the error is a "no rows" error
268268
if !errors.Is(err, pgx.ErrNoRows) {

flow/workflows/snapshot_flow.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,10 @@ func (s *SnapshotFlowExecution) closeSlotKeepAlive(
8383
s.logger.Info("closing slot keep alive for peer flow")
8484

8585
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
86-
StartToCloseTimeout: 10 * time.Minute,
86+
StartToCloseTimeout: 3 * time.Minute,
8787
RetryPolicy: &temporal.RetryPolicy{
8888
InitialInterval: 1 * time.Minute,
89+
MaximumAttempts: 3,
8990
},
9091
})
9192

@@ -94,7 +95,6 @@ func (s *SnapshotFlowExecution) closeSlotKeepAlive(
9495
}
9596

9697
s.logger.Info("closed slot keep alive for peer flow")
97-
9898
return nil
9999
}
100100

@@ -357,7 +357,6 @@ func SnapshotFlowWorkflow(
357357
if err := se.closeSlotKeepAlive(sessionCtx); err != nil {
358358
return fmt.Errorf("failed to close slot keep alive: %w", err)
359359
}
360-
361360
return nil
362361
}
363362

0 commit comments

Comments
 (0)