From 3881f395fdf25063a5f43eb529ea6c7a9fd61f0d Mon Sep 17 00:00:00 2001 From: nikifkon <90150140+nikifkon@users.noreply.github.com> Date: Wed, 30 Aug 2023 01:34:37 +0500 Subject: [PATCH] fix possible deadlock on big move (#291) --- pkg/datatransfers/data_transfers.go | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/pkg/datatransfers/data_transfers.go b/pkg/datatransfers/data_transfers.go index 0fb373c63..71224a87e 100644 --- a/pkg/datatransfers/data_transfers.go +++ b/pkg/datatransfers/data_transfers.go @@ -266,15 +266,16 @@ WHERE column_name=$1; qry := fmt.Sprintf("COPY (DELETE FROM %s.%s WHERE %s >= %s and %s <= %s RETURNING *) TO STDOUT", v.TableSchema, v.TableName, key.Entries()[0].Column, keyRange.LowerBound, key.Entries()[0].Column, keyRange.UpperBound) - _, err = txFrom.Conn().PgConn().CopyTo(ctx, &pw, qry) - if err != nil { - spqrlog.Zero.Error().Err(err).Msg("") - } - - if err := pw.w.Close(); err != nil { - spqrlog.Zero.Error().Err(err).Msg("error closing pipe") - } - + go func() { + _, err = txFrom.Conn().PgConn().CopyTo(ctx, &pw, qry) + if err != nil { + spqrlog.Zero.Error().Err(err).Msg("") + } + + if err := pw.w.Close(); err != nil { + spqrlog.Zero.Error().Err(err).Msg("error closing pipe") + } + }() _, err = txTo.Conn().PgConn().CopyFrom(ctx, r, fmt.Sprintf("COPY %s.%s FROM STDIN", v.TableSchema, v.TableName)) if err != nil {