diff --git a/replication.go b/replication.go index a3e58fa3..9bc4a1a4 100644 --- a/replication.go +++ b/replication.go @@ -377,7 +377,8 @@ func (rc *ReplicationConn) StartReplication(slotName string, startLsn uint64, ti return } - ctx, _ := context.WithTimeout(context.Background(), initialReplicationResponseTimeout) + ctx, cancelFn := context.WithTimeout(context.Background(), initialReplicationResponseTimeout) + defer cancelFn() // The first replication message that comes back here will be (in a success case) // a empty CopyBoth that is (apparently) sent as the confirmation that the replication has diff --git a/replication_test.go b/replication_test.go index 2c2d0af5..43793f3c 100644 --- a/replication_test.go +++ b/replication_test.go @@ -89,7 +89,8 @@ func TestSimpleReplicationConnection(t *testing.T) { for { var message *pgx.ReplicationMessage - ctx, _ := context.WithTimeout(context.Background(), time.Second) + ctx, cancelFn := context.WithTimeout(context.Background(), time.Second) + defer cancelFn() message, err = replicationConn.WaitForReplicationMessage(ctx) if err != nil && err != context.DeadlineExceeded { t.Fatalf("Replication failed: %v %s", err, reflect.TypeOf(err))