lib / pq

Pure Go Postgres driver for database/sql
https://pkg.go.dev/github.com/lib/pq
MIT License
9.04k stars 909 forks source link

Connection string parsing fails randomly #1138

Closed xROAL closed 11 months ago

xROAL commented 1 year ago

Unfortunately I am unable to pinpoint the issue or why it happens.

Sometimes, the connection fails with error pq: User "_float_digits" not found, where instead of user _float_digits, occasionaly you'll also see tyle, ase, or t_encoding.

Running the program mutliple times, it sometimes connects and sometimes not, the issue is sporadic.

Sample code:

package main

import (
    "database/sql"
    "log"

    _ "github.com/lib/pq"
)

func main() {
    connStr := "postgresql://user:pwd@host/dbname"
    db, err := sql.Open("postgres", connStr)
    if err != nil {
        log.Fatal(err)
    }

    err = db.Ping()
    if err != nil {
        log.Fatal(err)
    }

    err = db.Close()
    if err != nil {
        log.Fatal(err)
    }

    log.Print("ok")
}

Even when the connection fails, pq.ParseUrl is still able to parse the connection string correctly, meaning the error has to be elsewhere.

Go 1.21
Running on Windows 11 (22621)

I'm not using pq directly, but am using tools that rely on it, and this is really not fun to have happening. Has anyone seen/faced this as well?

johto commented 11 months ago

Can you actually reproduce it with the sample program? I don't have a Windows box around so I can't test there. I couldn't reproduce on OS X.

xROAL commented 11 months ago

Thank you for checking this.

After further testing, this seems to be an issue with a specific host only, as I started seeing this behavior with other drivers as well, but I can not reproduce it at all when using a different host.

Closing as this is not an issue in pq itself.