mirror of https://github.com/jackc/pgx.git
The tests for cancelling requests were failing when using unix sockets. The reason is that net.Conn.RemoteAddr() calls getpeername() to get the address. For Unix sockets, this returns the address that was passed to bind() by the *server* process, not the address that was passed to connect() by the *client*. For postgres, this is always relative to the server's directory, so is a path like: ./.s.PGSQL.5432 Since it does not return the full absolute path, this function cannot connect, so it cannot cancel requests. To fix it, use the connection's config for Unix sockets. I think this should be okay, since a system using unix sockets should not have "fallbacks". If that is incorrect, we will need to save the address on PgConn. Fixes the following failed tests when using Unix sockets: --- FAIL: TestConnCancelRequest (2.00s) pgconn_test.go:2056: Error Trace: /Users/evan.jones/pgx/pgconn/pgconn_test.go:2056 /Users/evan.jones/pgx/pgconn/asm_arm64.s:1172 Error: Received unexpected error: dial unix ./.s.PGSQL.5432: connect: no such file or directory Test: TestConnCancelRequest pgconn_test.go:2063: Error Trace: /Users/evan.jones/pgx/pgconn/pgconn_test.go:2063 Error: Object expected to be of type *pgconn.PgError, but was <nil> Test: TestConnCancelRequest --- FAIL: TestConnContextCanceledCancelsRunningQueryOnServer (5.10s) pgconn_test.go:2109: Error Trace: /Users/evan.jones/pgx/pgconn/pgconn_test.go:2109 Error: Received unexpected error: timeout: context already done: context deadline exceeded Test: TestConnContextCanceledCancelsRunningQueryOnServer |
||
---|---|---|
.. | ||
internal/ctxwatch | ||
README.md | ||
auth_scram.go | ||
benchmark_private_test.go | ||
benchmark_test.go | ||
config.go | ||
config_test.go | ||
defaults.go | ||
defaults_windows.go | ||
doc.go | ||
errors.go | ||
errors_test.go | ||
export_test.go | ||
helper_test.go | ||
krb5.go | ||
pgconn.go | ||
pgconn_private_test.go | ||
pgconn_stress_test.go | ||
pgconn_test.go |
README.md
pgconn
Package pgconn is a low-level PostgreSQL database driver. It operates at nearly the same level as the C library libpq. It is primarily intended to serve as the foundation for higher level libraries such as https://github.com/jackc/pgx. Applications should handle normal queries with a higher level library and only use pgconn directly when required for low-level access to PostgreSQL functionality.
Example Usage
pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
if err != nil {
log.Fatalln("pgconn failed to connect:", err)
}
defer pgConn.Close(context.Background())
result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
for result.NextRow() {
fmt.Println("User 123 has email:", string(result.Values()[0]))
}
_, err = result.Close()
if err != nil {
log.Fatalln("failed reading result:", err)
}
Testing
See CONTRIBUTING.md for setup instructions.