-
Notifications
You must be signed in to change notification settings - Fork 888
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stack overflows on upgrading from 5.6.0 to 5.7.1 #2141
Comments
I used git bisect and found that the issue was introduced in 5747f37. I've also found that json(b) has nothing to do with it. Still investigating. |
I'm also able to reproduce it with pgx directly without going through stdlib. |
I've now been able to reproduce it without New repro code: package main
import (
"context"
"fmt"
"log"
"os"
"github.com/jackc/pgx/v5"
)
func main() {
conn, err := pgx.Connect(context.Background(), os.Getenv("DATABASE_URL"))
defer conn.Close(context.Background())
uuid := [16]byte{}
var exists bool
err = conn.QueryRow(
context.Background(),
`SELECT 'foobar' = $1`,
uuid,
).Scan(&exists)
if err != nil {
log.Fatal(err)
}
fmt.Println("Exists:", exists)
} |
Okay, I think I understand what is going on now. pgx tries really hard to "just work" with whatever types you use. Part of how that works is when it doesn't know how to encode a particular Go type into a particular PostgreSQL type it tries various strategies to convert the Go value into a type that it does know how to handle. For example, it will dereference pointers and it convert values into their underlying types. For example, for This process is attempted recursively. Here lies the problem. Your query is not actually attempting to send a I've implemented a depth check to the planning systems for encoding and scanning where they will give up when they reach a certain level. See 123b59a. This should resolve the issue. |
This also occurs when doing something like package main
import (
"context"
"fmt"
"log"
"os"
"github.com/gofrs/uuid/v5"
pgxuuid "github.com/jackc/pgx-gofrs-uuid"
"github.com/jackc/pgx/v5"
)
func main() {
ctx := context.Background()
conn, err := pgx.Connect(ctx, os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatal(err)
}
defer conn.Close(ctx)
pgxuuid.Register(conn.TypeMap())
uuid1 := uuid.Must(uuid.NewV4())
var uuid2 *uuid.UUID
var r *uuid.UUID
if err := conn.QueryRow(
ctx,
`SELECT COALESCE($2, $1)`,
uuid1,
uuid2,
).Scan(&r); err != nil {
log.Fatal(err)
}
fmt.Println("ret:", r)
} Edit: my actual code did something like |
I got the same issue with a "SELECT ... WHERE ref=$1" statement. In my case, the column ref is a varchar, while the argument for $1 is a UUID. I understand that the argument has wrong type, but that should not cause a stack overflow. Waiting for the next release. Thanks for fixing it. Edit: We used pgx v5.5.4 before, which worked with the UUID. The SQL queries executed successfully. |
Describe the bug
After upgrading from 5.6.0 to 5.7.1 the following program results in a stackoverflow. It seems somewhat related to #1331 (stackoverflow that requires
pgx-google-uuid
) and #2125 (custom type and jsonb, although they state that issue is in 5.6.0 whereas my issue did not occur in 5.6.0).To Reproduce
Expected behavior
Actual behavior
Version
go version go1.23.1 linux/amd64
PostgreSQL 16.4 (Ubuntu 16.4-1.pgdg20.04+2) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0, 64-bit
v5.7.1
The text was updated successfully, but these errors were encountered: