Skip to content

Open() DSN has race condition when using "database" rather than "dbname" #856

@felixge

Description

@felixge

The following works reliably:

db, err := sql.Open("postgres", "dbname=my_db")
if err == nil {
  err = db.Ping()
}
// err should be nil if my_db exists

However the following will randomly use the value of the PGDATABASE environment variable instead of the given DSN.

db, err := sql.Open("postgres", "database=my_db")
if err == nil {
  err = db.Ping()
}
// err should be nil if my_db exists

This seems to be due to lib/pq implicitly relying on predictable map iteration internally, which Go does not provide.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions