jackc / pgx

PostgreSQL driver and toolkit for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pgx doesn't cancel query correctly through pgbouncer

levakin opened this issue · comments

Describe the bug
12b177f causes queries not being cancelled corretly through the PGBouncer. It's not sufficient to only write in the connection.

To Reproduce
Test is updated also to check cancellation of queries through the PGBouncer.

Steps to reproduce the behavior:

  1. Run long query and cancel it
package main

import (
	"context"
	"log"
	"os"

	"github.com/jackc/pgx/v5"
)

func main() {
	conn, err := pgx.Connect(context.Background(), os.Getenv("PGX_TEST_PGBOUNCER_CONN_STRING"))
	if err != nil {
		log.Fatal(err)
	}
	defer conn.Close(context.Background())
        
        ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
	defer cancel()
	
	err = conn.Query(ctx, "select pg_sleep(30)")
}
  1. Check pg_stat_activity
select * from pg_stat_activity where state='active';

Expected behavior
Queries should be cancelled when using PGbouncer as it works with PostgreSQL directly.

Actual behavior
Queries remain active in pg_stat_activity

Version

  • Go: go1.21.2 darwin/amd64
  • PGBouncer: 1.20.1
  • PostgreSQL: PostgreSQL 15.3 on x86_64-pc-linux-musl, compiled by gcc (Alpine 12.2.1_git20220924-r4) 12.2.1 20220924, 64-bit
  • pgx: v5.4.3

@jackc hi, could you please create a hotfix release for this bug?

hi @jackc This hotfix is important for my project. What is the expected release date v5.4.4? Or do you plan to include it only in v5.5.0? Thanks!

Just v.5.5.0. I plan on tagging that either this weekend or the next.