diff --git a/batch.go b/batch.go index c5b1d32d..ca77dd6d 100644 --- a/batch.go +++ b/batch.go @@ -90,10 +90,6 @@ func (b *Batch) Send(ctx context.Context) error { return err } - if err := b.conn.ensureConnectionReadyForQuery(); err != nil { - return err - } - batch := &pgconn.Batch{} for _, bi := range b.items { diff --git a/conn.go b/conn.go index 1609344e..78716cdf 100644 --- a/conn.go +++ b/conn.go @@ -78,9 +78,8 @@ type Conn struct { status byte // One of connStatus* constants causeOfDeath error - pendingReadyForQueryCount int // number of ReadyForQuery messages expected - cancelQueryCompleted chan struct{} - lastStmtSent bool + cancelQueryCompleted chan struct{} + lastStmtSent bool // context support ctxInProgress bool @@ -498,10 +497,6 @@ func (c *Conn) PrepareEx(ctx context.Context, name, sql string, opts *PrepareExO } } - if err := c.ensureConnectionReadyForQuery(); err != nil { - return nil, err - } - if c.shouldLog(LogLevelError) { defer func() { if err != nil { @@ -569,10 +564,6 @@ func (c *Conn) deallocateContext(ctx context.Context, name string) (err error) { err = c.termContext(err) }() - if err := c.ensureConnectionReadyForQuery(); err != nil { - return err - } - delete(c.preparedStatements, name) _, err = c.pgConn.Exec(ctx, "deallocate "+quoteIdentifier(name)).ReadAll() @@ -635,8 +626,6 @@ func (c *Conn) processContextFreeMsg(msg pgproto3.BackendMessage) (err error) { switch msg := msg.(type) { case *pgproto3.ErrorResponse: return c.rxErrorResponse(msg) - case *pgproto3.ReadyForQuery: - c.rxReadyForQuery(msg) } return nil @@ -670,10 +659,6 @@ func (c *Conn) rxErrorResponse(msg *pgproto3.ErrorResponse) *pgconn.PgError { return err } -func (c *Conn) rxReadyForQuery(msg *pgproto3.ReadyForQuery) { - c.pendingReadyForQueryCount-- -} - func (c *Conn) rxRowDescription(msg *pgproto3.RowDescription) []FieldDescription { fields := make([]FieldDescription, len(msg.Fields)) for i := 0; i < len(fields); i++ { @@ -872,7 +857,7 @@ func (c *Conn) WaitUntilReady(ctx context.Context) error { if err != nil { return err } - return c.ensureConnectionReadyForQuery() + return nil } func (c *Conn) waitForPreviousCancelQuery(ctx context.Context) error { @@ -891,30 +876,6 @@ func (c *Conn) waitForPreviousCancelQuery(ctx context.Context) error { } } -func (c *Conn) ensureConnectionReadyForQuery() error { - for c.pendingReadyForQueryCount > 0 { - msg, err := c.pgConn.ReceiveMessage() - if err != nil { - return err - } - - switch msg := msg.(type) { - case *pgproto3.ErrorResponse: - pgErr := c.rxErrorResponse(msg) - if pgErr.Severity == "FATAL" { - return pgErr - } - default: - err = c.processContextFreeMsg(msg) - if err != nil { - return err - } - } - } - - return nil -} - func connInfoFromRows(rows *Rows, err error) (map[string]pgtype.OID, error) { if err != nil { return nil, err @@ -964,10 +925,6 @@ func (c *Conn) Exec(ctx context.Context, sql string, arguments ...interface{}) ( } defer c.unlock() - if err := c.ensureConnectionReadyForQuery(); err != nil { - return "", err - } - startTime := time.Now() commandTag, err := c.exec(ctx, sql, arguments...) diff --git a/fastpath.go b/fastpath.go index bee0dd0a..a6a4de8a 100644 --- a/fastpath.go +++ b/fastpath.go @@ -52,10 +52,6 @@ func fpInt64Arg(n int64) fpArg { } func (f *fastpath) Call(oid pgtype.OID, args []fpArg) (res []byte, err error) { - if err := f.cn.ensureConnectionReadyForQuery(); err != nil { - return nil, err - } - buf := f.cn.wbuf buf = append(buf, 'F') // function call sp := len(buf) @@ -76,8 +72,6 @@ func (f *fastpath) Call(oid pgtype.OID, args []fpArg) (res []byte, err error) { return nil, err } - f.cn.pendingReadyForQueryCount++ - for { msg, err := f.cn.pgConn.ReceiveMessage() if err != nil { @@ -88,7 +82,6 @@ func (f *fastpath) Call(oid pgtype.OID, args []fpArg) (res []byte, err error) { res = make([]byte, len(msg.Result)) copy(res, msg.Result) case *pgproto3.ReadyForQuery: - f.cn.rxReadyForQuery(msg) // done return res, err default: diff --git a/query.go b/query.go index ec48db9b..0ba075d6 100644 --- a/query.go +++ b/query.go @@ -361,11 +361,6 @@ func (c *Conn) QueryEx(ctx context.Context, sql string, options *QueryExOptions, return rows, err } - if err := c.ensureConnectionReadyForQuery(); err != nil { - rows.fatal(err) - return rows, err - } - if err := c.lock(); err != nil { rows.fatal(err) return rows, err