2
0

Set socket to non-blocking mode before doneChan is allocated to avoid that channel leaked in case when SetBlockingMode will return error

This commit is contained in:
Dmitry K
2023-03-18 22:17:08 +03:00
committed by Jack Christensen
parent a83faa67f5
commit 3db7d1774e
+3 -3
View File
@@ -132,9 +132,6 @@ func (ct *copyFrom) run(ctx context.Context) (int64, error) {
return 0, fmt.Errorf("unknown QueryExecMode: %v", ct.mode)
}
r, w := io.Pipe()
doneChan := make(chan struct{})
if realNbConn, ok := ct.conn.pgConn.Conn().(*nbconn.NetConn); ok {
if err := realNbConn.SetBlockingMode(false); err != nil {
return 0, fmt.Errorf("cannot set socket non-blocking mode: %w", err)
@@ -146,6 +143,9 @@ func (ct *copyFrom) run(ctx context.Context) (int64, error) {
}()
}
r, w := io.Pipe()
doneChan := make(chan struct{})
go func() {
defer close(doneChan)