Describe the bug
pgconn.ParseConfigWithOptions appears to call defaultSettings() before parsing and merging the connection string. defaultSettings() calls os/user.Current() to populate the default PostgreSQL user / passfile / servicefile.
This means os/user.Current() is called even when the connection string explicitly contains user=....
In minimal/distroless container environments this can crash during CGO user lookup before the provided PostgreSQL user is applied.
To Reproduce
Call pgconn.ParseConfigWithOptions within a distroless Docker container with CGO enabled which will subsequently use the crashing libc implementation of user.Current().
Expected behavior
If the connection string or environment explicitly provides user, pgx should not need to call os/user.Current() to determine a default user.
Ideally, user lookup would be lazy / conditional:
- parse connection string
- parse environment
- merge provided settings
- only call
os/user.Current() if user, passfile, or servicefile defaults are actually needed
Actual behavior
pgx eagerly looks up default OS-user-derived information even when that information is not needed, because the PostgreSQL user has already been explicitly configured. The crash is the visible symptom, but the pgx behavior concern is the unnecessary eager lookup of default information before knowing whether those defaults are required.
Stack trace excerpt:
SIGFPE: floating-point exception
signal arrived during cgo execution
os/user._Cfunc_mygetpwuid_r(...)
os/user.lookupUnixUid(...)
os/user.current()
os/user.Current()
github.com/jackc/pgx/v5/pgconn.defaultSettings()
github.com/jackc/pgx/v5/pgconn.ParseConfigWithOptions(...)
Version
- Go:
go1.26.4 linux/amd64
- pgx:
v5.10.0
- Go build uses CGO, so
os/user.Current() uses the libc lookup
Additional context
Any of these workarounds avoids or mitigates the issue:
- build with
-tags osusergo
- build with
CGO_ENABLED=0, if possible
Describe the bug
pgconn.ParseConfigWithOptionsappears to calldefaultSettings()before parsing and merging the connection string.defaultSettings()callsos/user.Current()to populate the default PostgreSQL user / passfile / servicefile.This means
os/user.Current()is called even when the connection string explicitly containsuser=....In minimal/distroless container environments this can crash during CGO user lookup before the provided PostgreSQL user is applied.
To Reproduce
Call
pgconn.ParseConfigWithOptionswithin a distroless Docker container with CGO enabled which will subsequently use the crashing libc implementation ofuser.Current().Expected behavior
If the connection string or environment explicitly provides
user, pgx should not need to callos/user.Current()to determine a default user.Ideally, user lookup would be lazy / conditional:
os/user.Current()ifuser,passfile, orservicefiledefaults are actually neededActual behavior
pgx eagerly looks up default OS-user-derived information even when that information is not needed, because the PostgreSQL user has already been explicitly configured. The crash is the visible symptom, but the pgx behavior concern is the unnecessary eager lookup of default information before knowing whether those defaults are required.
Stack trace excerpt:
Version
go1.26.4 linux/amd64v5.10.0os/user.Current()uses the libc lookupAdditional context
Any of these workarounds avoids or mitigates the issue:
-tags osusergoCGO_ENABLED=0, if possible