Commit Graph

124 Commits (e4f72071f89b69037193e5eb2b12f4cd0847861e)

Author SHA1 Message Date
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
Brandon Kauffman 1dd69f86a1 Enable failover efforts when pg_hba.conf disallows non-ssl connections
Copy of https://github.com/jackc/pgconn/pull/133
2023-06-24 06:41:35 -05:00
Jack Christensen 0d14b87140 Because CI runs on a potato 2023-06-20 08:43:06 -05:00
Jack Christensen 5b7cc8e215 Make TestConnCheckConn less timing sensitive for CI 2023-06-17 17:12:58 -05:00
Nicola Murino b1f8055584 TestConnectWithFallback: increase timeout
on Windows connecting on a closed port takes about 2 seconds.
You can test with something like this

        start := time.Now()
	_, err := d.DialContext(context.Background(), "tcp", "127.0.0.1:1")
	fmt.Printf("finished, time %s, err: %v\n", time.Since(start), err)

This seems by design

https://groups.google.com/g/comp.os.ms-windows.programmer.win32/c/jV6kRVY3BqM

Generally TestConnectWithFallback takes about 8-9 seconds on Windows.
Increase timeout to avoid random failures under load
2023-06-15 20:54:24 -05:00
Jack Christensen 5f28621394 Add docs clarifying that FieldDescriptions may return nil
https://github.com/jackc/pgx/issues/1634
2023-06-14 07:42:11 -05:00
Jack Christensen 34eddf9983 Increase slowWriteTimer to 15ms and document why 2023-06-12 09:39:26 -05:00
Jack Christensen 5d4f9018bf failed to write startup message error should be normalized 2023-06-12 09:39:26 -05:00
Jack Christensen 482e56a79b Fix race condition when CopyFrom is cancelled. 2023-06-12 09:39:26 -05:00
Jack Christensen 3ea2f57d8b Deprecate CheckConn in favor of Ping 2023-06-12 09:39:26 -05:00
Jack Christensen 26c79eb215 Handle writes that could deadlock with reads from the server
This commit adds a background reader that can optionally buffer reads.
It is used whenever a potentially blocking write is made to the server.
The background reader is started on a slight delay so there should be no
meaningful performance impact as it doesn't run for quick queries and
its overhead is minimal relative to slower queries.
2023-06-12 09:39:26 -05:00