Commit Graph

134 Commits (7fceb64deee5adddfcb40abacd271a74a596fca5)

Author SHA1 Message Date
Yann Soubeyrand c407c42692 Add support for sslrootcert=system 2024-06-25 11:15:40 +02:00
Hans-Joachim Kliemeck 24c0a5e8ff remove keepalive and rely on GOLANG default (since go 1.13 default is 15s)
https://www.reddit.com/r/golang/comments/d7v7dn/psa_go_113_introduces_15_sec_server_tcp/
2024-05-21 10:37:13 -05:00
Jack Christensen ded01c0cd9 Fix TestParseConfigEnvLibpq unsetting envars
This would cause tests to fail if PG* variables were used for the
default connection config for other tests.

Previously broken by 0080acf318.
2024-05-17 09:19:36 -05:00
Oleksandr Redko c05cce7d41 Fix test asserts: reverse expected-actual 2024-05-14 20:07:10 -05:00
Oleksandr Redko 0080acf318 Simplify config tests by using T.Setenv, T.TempDir 2024-05-14 20:06:18 -05:00
Jack Christensen a966716860 Replace DSN with keyword/value in comments and documentation
The term DSN is not used in the PostgreSQL documentation. I'm not sure
why it was originally used. Use the correct PostgreSQL terminology.
2024-05-11 14:33:35 -05:00
Jack Christensen cf50c60869 Fix error check on CI 2024-05-11 14:33:13 -05:00
Jack Christensen 8db971660e Failed connection attempts include all errors
A single Connect("connstring") may actually make multiple connection
requests due to TLS or HA configuration. Previously, when all attempts
failed only the last error was returned. This could be confusing.
Now details of all failed attempts are included.

For example, the following connection string:

host=localhost,127.0.0.1,foo.invalid port=1,2,3

Will now return an error like the following:

failed to connect to `user=postgres database=pgx_test`:
	lookup foo.invalid: no such host
	[::1]:1 (localhost): dial error: dial tcp [::1]:1: connect: connection refused
	127.0.0.1:1 (localhost): dial error: dial tcp 127.0.0.1:1: connect: connection refused
	127.0.0.1:2 (127.0.0.1): dial error: dial tcp 127.0.0.1:2: connect: connection refused

https://github.com/jackc/pgx/issues/1929
2024-05-11 14:25:03 -05:00
Jack Christensen 579a320c1c pgconn.SafeToRetry checks for wrapped errors
Use errors.As instead of type assertion.

Port 4e2e7a040579c1999c0766642d836eb28c6e2018 to v5

Credit to tjasko
2024-05-09 17:59:16 -05:00
Jack Christensen 48ae1f4b2c Fix ResultReader.Read() to handle nil values
The ResultReader.Read() method was erroneously converting nil values
to []byte{}.

https://github.com/jackc/pgx/issues/1987
2024-05-09 17:13:26 -05:00
Jack Christensen 6f0deff015 Add custom data to pgconn.PgConn
https://github.com/jackc/pgx/issues/1896
2024-05-09 15:39:28 -05:00
Jack Christensen c31619d08b Improve docs for customizing context cancellation 2024-05-08 08:08:21 -05:00
Jack Christensen ec9bb2ace7 Improve flickering test on CI 2024-05-08 07:54:17 -05:00
Jack Christensen 93a579754b Add CancelRequestContextWatcherHandler
This allows a context to cancel a query by sending a cancel request to
the server before falling back to setting a deadline.
2024-05-08 07:41:02 -05:00
Jack Christensen 42c9e9070a Allow customizing context canceled behavior for pgconn
This feature made the ctxwatch package public.
2024-05-08 07:41:02 -05:00
Oleksandr Redko 60a01d044a Fix typos in doc comments 2024-04-17 12:00:02 -05:00
Jack Christensen a3d9120636 Add SeverityUnlocalized field to PgError / Notice
https://github.com/jackc/pgx/issues/1971
2024-04-07 08:58:10 -05:00
Jack Christensen adbb38f298 Do not allow protocol messages larger than ~1GB
The PostgreSQL server will reject messages greater than ~1 GB anyway.
However, worse than that is that a message that is larger than 4 GB
could wrap the 32-bit integer message size and be interpreted by the
server as multiple messages. This could allow a malicious client to
inject arbitrary protocol messages.

https://github.com/jackc/pgx/security/advisories/GHSA-mrww-27vc-gghv
2024-03-04 09:09:29 -06:00
Jack Christensen 2e84dccaf5 *Pipeline.getResults should close pipeline on error
Otherwise, it might be possible to panic when closing the pipeline if it
tries to read a connection that should be closed but still has a fatal
error on the wire.

https://github.com/jackc/pgx/issues/1920
2024-02-29 18:44:01 -06:00
Jack Christensen 8896bd6977 Handle invalid sslkey file
https://github.com/jackc/pgx/issues/1915
2024-02-24 09:24:26 -06:00
Jack Christensen f654d61d79 Make note about possible parse config error message redaction change 2024-01-12 17:56:13 -06:00
Jack Christensen 5d26bbefd8 Make pgconn.ConnectError and pgconn.ParseConfigError public
fixes #1773
2024-01-12 17:52:25 -06:00
vahid-sohrabloo 44768b5a01 fix a typo in config_test.go
fix a typo in config_test.go
2024-01-12 17:36:43 -06:00
Jack Christensen cbc5a7055f Fix: close conn on read failure in pipeline
Suggested by @jameshartig in https://github.com/jackc/pgx/issues/1847
2023-12-23 12:11:23 -06:00
James Hartig 22fe50149b pgconn: check if pipeline i closed in Sync/GetResults
Otherwise there will be a nil pointer exception accessing the conn
2023-12-23 12:04:21 -06:00
Ryan Fowler dfd198003a Fix panic in Pipeline when PgConn is busy or closed 2023-12-23 10:30:59 -06:00
Samuel Stauffer 9ab9e3c40b Unwrap errors in normalizeTimeoutError 2023-12-16 11:15:35 -06:00
Samuel Stauffer 2daeb8dc5f pgconn: normalize starTLS connection error
Normalize the error that is returned by startTLS in pgconn.connect. This
makes it possible to determine if the error was a context error.
2023-12-16 11:15:35 -06:00
Jack Christensen df3c5f4df8 Use "Pg" instead of "PG" in new PgError related identifiers
Arguably, PGError might have been better. But since the precedent is
long since established it is better to be consistent.
2023-12-15 18:33:51 -06:00
James Hartig b1631e8e35 pgconn: add OnPGError to Config for error handling
OnPGError is called on every error response received from Postgres and can
be used to close connections on specific errors. Defaults to closing on
FATAL-severity errors.

Fixes #1803
2023-12-15 18:29:32 -06:00
Simon Paredes 89d699c2e8 wrap errors instead of just formatting them 2023-12-01 18:23:23 -06:00
Jack Christensen 7d5a3969d0 Improve docs and tests 2023-11-18 07:44:24 -06:00
Jack Christensen 4dbd57a7ed Add PgConn.Deallocate method
This method uses the PostgreSQL protocol Close method to deallocate a
prepared statement. This means that it can succeed in an aborted
transaction.
2023-11-18 07:44:24 -06:00
Jack Christensen 0570b0e196 Better document PgConn.Prepare implementation 2023-11-18 07:44:24 -06:00
Ivan Posazhennikov 6f7400f428 fix typo in the comment in the pgconn.go 2023-10-14 18:02:35 -05:00
Anton Levakin 304697de36 CancelRequest: Wait for the cancel request to be acknowledged by the server 2023-10-14 17:48:16 -05:00
Anton Levakin 5d0f904831 update TestConnContextCanceledCancelsRunningQueryOnServer
Check cancellation of the request for pgbouncer
2023-10-14 17:48:16 -05:00
Anton Levakin 6ca3d8ed4e Revert "CancelRequest: don't try to read the reply"
This reverts commit c861bce438.
2023-10-14 17:48:16 -05:00
Jack Christensen 81ddcfdefb Fix spurious deadline exceeded error
stdlib_test.TestConnConcurrency had been flickering on CI deadline /
timeout errors. This was extremely confusing because the test deadline
was set for 2 minutes and the errors would occur much quicker.

The problem only manifested in an extremely specific and timing
sensitive situation.

1. The watchdog timer for deadlocked writes starts the goroutine to
   start the background reader
2. The background reader is stopped
3. The next operation is a read without a preceding write (AFAIK only
   CheckConn does this)
4. The deadline is set to interrupt the read
5. The goroutine from 1 actually starts the background reader
6. The background reader gets an error reading the connection with the
   deadline
7. The deadline is cleared
8. The next read on the connection will get the timeout error
2023-10-14 11:38:33 -05:00
Ville Skyttä c6c50110db Spelling and grammar fixes 2023-10-07 09:26:23 -05:00
Jack Christensen 91530db629 Fix typo in string.Cut refactor 2023-10-07 09:20:28 -05:00
Ville Skyttä 24ed0e4257 Make use of strings.Cut 2023-10-04 20:41:55 +03:00
Jack Christensen 163eb68866 Normalize timeout error when receiving pipeline results
https://github.com/jackc/pgx/issues/1748#issuecomment-1740437138
2023-09-30 08:50:40 -05:00
Alexey Palazhchenko 8fb309c631 Use Go 1.20's link syntax for `ParseConfig` 2023-07-28 17:51:42 -05:00
smaher-edb f47f0cf823 connect_timeout is not obeyed for sslmode=allow|prefer
connect_timeout given in conn string was not obeyed if sslmode is not specified (default is prefer) or equals sslmode=allow|prefer. It took twice the amount of time specified by connect_timeout in conn string. While this behavior is correct if multi-host is provided in conn string, it doesn't look correct in case of single host. This behavior was also not matching with libpq.

The root cause was to implement sslmode=allow|prefer conn are tried twice. First with TLSConfig and if that doesn't work then without TLSConfig. The fix for this issue now uses the same context if same host is being tried out. This change won't affect the existing multi-host behavior.

This PR goal is to close issue [jackc/pgx/issues/1672](https://github.com/jackc/pgx/issues/1672)
2023-07-15 09:49:09 -05:00
Jack Christensen 95aa87f2e8 exitPotentialWriteReadDeadlock stops bgReader
It's not enough to stop the slowWriteTimer, because the bgReader may
have been started.
2023-07-11 21:29:11 -05:00
Jack Christensen f512b9688b Add PgConn.SyncConn
This provides a way to ensure it is safe to directly read or write to
the underlying net.Conn.

https://github.com/jackc/pgx/issues/1673
2023-07-11 21:29:11 -05:00
Jack Christensen 05440f9d3f Drastically increase allowed test times for potato CI
The context timeouts for tests are designed to give a better error
message when something hangs rather than the test just timing out.
Unfortunately, the potato CI frequently has some test or another
randomly take a long time. While the increased times are somewhat less
than optimal on a real computer, hopefully this will solve the
flickering CI.
2023-07-11 21:16:08 -05:00
Jack Christensen cd46cdd450 Recreate the frontend in Construct with the new bgReader
https://github.com/jackc/pgx/pull/1629#discussion_r1251472215
2023-07-08 11:39:39 -05:00
Adrian-Stefan Mares 2bf5a61401 fix: Do not use infinite timers 2023-07-08 11:24:39 -05:00