Fix Windows non-blocking I/O for CopyFrom
Created based on discussion here: https://github.com/jackc/pgx/pull/1525#pullrequestreview-1344511991 Fixes https://github.com/jackc/pgx/issues/1552
This commit is contained in:
committed by
Jack Christensen
parent
9ae852eb58
commit
8b5e8d9d89
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jackc/pgx/v5/internal/nbconn"
|
||||
"io"
|
||||
|
||||
"github.com/jackc/pgx/v5/internal/pgio"
|
||||
@@ -134,6 +135,17 @@ func (ct *copyFrom) run(ctx context.Context) (int64, error) {
|
||||
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)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
// TODO: Deal with it
|
||||
_ = realNbConn.SetBlockingMode(true)
|
||||
}()
|
||||
}
|
||||
|
||||
go func() {
|
||||
defer close(doneChan)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user