Fix leaked contexts

v3-experimental
Jack Christensen 2017-02-16 18:11:30 -06:00
parent efcc172c8b
commit c540b65edf
2 changed files with 4 additions and 2 deletions

View File

@ -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

View File

@ -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))