Similarly to PGconn, PGcancelConn must not be used after .finish(); we
raise an OperationalError to prevent segfault when the connection
pointer is NULL.
We split the previous (misnamed) test_cancel_nonblocking() into
test_cancel_conn_blocking() and test_cancel_conn_nonblocking()
respectively checking PQcancelBlocking() and
PQcancelStart()/PQcancelPoll().
The cancellable_query() is now responsible for creating the monitor_conn
and uses a PGconn value, coming from the pgconn fixture in tests.
Denis Laxalde [Thu, 23 Mar 2023 12:51:16 +0000 (13:51 +0100)]
feat: add libpq interface for encrypted and non-blocking cancellation
Encrypted and non-blocking cancellation should be part PostgreSQL 17:
- https://commitfest.postgresql.org/37/3511/
- https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=61461a300c1cb5d53955ecd792ad0ce75a104736
We here add the interface for libpq functions for this feature.
An extra test is introduced, it closely reproduces
src/test/modules/libpq_pipeline/libpq_pipeline::test_cancel() in
PostgreSQL test suite.
The error_message property of PGcancelConn is directly an str and
PGcancelConn has no encoding specified and all messages come from the
client (libpq).
Daniele Varrazzo [Fri, 26 Jan 2024 09:47:31 +0000 (09:47 +0000)]
refactor: handle timeout in the connection generator, not the waiting function
The waiting function is supposed to be generic, the timeout is a policy
decision of the generator.
This change aligns the semantics of the `timeout` parameter of `wait_conn()`
to the one of the other wait functions: the timeout is actually an
interval. It will be renamed to clarify that in a followup commit.
docs: let the 'pq' role possibly link to "devel" PostgreSQL docs
If we now set libpq_docs_version to 'devel', the pq Sphinx role will use
the master branch when looking libpq.sgml and the 'devel' URL component
when linking to libpq online documentation.
Daniele Varrazzo [Sun, 31 Mar 2024 20:57:42 +0000 (20:57 +0000)]
fix: more careful stripping of error prefixes
Only strip the known prefixes, both in English and in the currently
known localizations.
Added script to generate regexp to match every backend localization. The
script was executed on PostgreSQL commit f4ad0021af (on master branch,
before v17).
Denis Laxalde [Mon, 4 Mar 2024 07:37:58 +0000 (08:37 +0100)]
feat(tools): check last modification times in async_to_sync.py
We now only process _async.py files with a modification time higher than
their sync counterpart. A -B,--convert-all option is added to force
conversion of all (specified) input files and skip last-modification
time check.
fix: avoid to create reference loops in datetime adapters
Setting the reference to a bound method in the state creates a reference
loop.
The issue is minimal because the gc will be able to break these loops
anyway and because it mostly happens with exotic or unsupported
date/interval styles.
Daniele Varrazzo [Fri, 26 Jan 2024 09:47:31 +0000 (09:47 +0000)]
refactor: handle timeout in the connection generator, not the waiting function
The waiting function is supposed to be generic, the timeout is a policy
decision of the generator.
This change aligns the semantics of the `timeout` parameter of `wait_conn()`
to the one of the other wait functions: the timeout is actually an
interval. It will be renamed to clarify that in a followup commit.
Daniele Varrazzo [Wed, 24 Jan 2024 19:51:30 +0000 (19:51 +0000)]
fix: include timeout as part of the generators/wait conversation
So far, the wait functions would have shielded the generators from a
wait timeout. However this behaviour makes impossible to make a
generator interruptible.
Note that the `wait_c` generator was interruptible, but probably it
wasn't doing the right thing. In the `poll` branch, I understand that
the returned ready value, in case of timeout, would have been the same
of the input wait value, because of the input/output nature of the
pollfd struct; I haven't analyzed more deeply the select() case.
Michał Górny [Sat, 27 Jan 2024 14:28:34 +0000 (15:28 +0100)]
fix: add `libc.so` fallback for musl systems to the ctypes impl
Add a fallback to `libc.so` library name to fix loading the ctypes
implementation on musl systems. On musl, `find_library("c")` does
not work (the problem has been reported to CPython in 2014, and has not
been resolved yet), causing the module to fail on `assert libcname`.
Instead, add a fallback to using `libc.so` and let ctypes raise
an exception if such a library does not exist.
It was imported directly by typing_extensions to work around
https://github.com/microsoft/pyright/issues/4197
but the issue has been fixed in pyright 1.1.297, released almost one
year ago.
fix: perform multiple attemps if a host name resolve to multiple hosts
We now perform DNS resolution in Python both in the sync and async code.
Because the two code paths are now very similar, make sure they pass the
same tests.
Daniele Varrazzo [Fri, 29 Dec 2023 23:41:07 +0000 (00:41 +0100)]
fix(pool): use an exponential backoff to separate failing checks
This is a consistent behaviour with with the exponential backoff used in
reconnection attempts, and actually we could reuse the same object
implementing the backoff + jitter.
fix: define the Row TypeVar as defaulting to TupleRow
This allows to return `Self` uniformly from the `Connection.connect()` class
method, which in turns allows to subclass the connection without the
need of redefining the complex signature.
Daniele Varrazzo [Wed, 13 Dec 2023 13:20:49 +0000 (14:20 +0100)]
refactor: add compiled_default option to _get_params
Make it less awkward to come out with a 5432 when we really want a port
number (in name resolution) but still allow to leave it unspecified to
avoid mangling the conninfo.