]> git.ipfire.org Git - thirdparty/psycopg.git/log
thirdparty/psycopg.git
3 months agotest(pool): verify the overriding of `close()` to act as `putconn()` maint-pool-3.2
Daniele Varrazzo [Wed, 16 Apr 2025 18:57:37 +0000 (20:57 +0200)] 
test(pool): verify the overriding of `close()` to act as `putconn()`

We would like to maintain this possibility on a best-effort basis. The
hack has been mentioned in #1046 and upstream in
https://github.com/sqlalchemy/sqlalchemy/discussions/12522 and is useful
to integrate psycopg pool with the SQLAlchemy NullPool.

5 months agoops: don't run pre-commit on version bump
Daniele Varrazzo [Tue, 25 Feb 2025 21:09:39 +0000 (22:09 +0100)] 
ops: don't run pre-commit on version bump

Pre-commit is not installed in this branch.

5 months agochore: bump psycopg_pool package version to 3.2.6 pool-3.2.6
Daniele Varrazzo [Tue, 25 Feb 2025 21:08:48 +0000 (22:08 +0100)] 
chore: bump psycopg_pool package version to 3.2.6

5 months agoMerge branch 'fix-transaction-after-check' into maint-pool-3.2
Daniele Varrazzo [Tue, 25 Feb 2025 21:07:11 +0000 (22:07 +0100)] 
Merge branch 'fix-transaction-after-check' into maint-pool-3.2

5 months agodocs(pool): add release note about ticket #1014
Daniele Varrazzo [Tue, 25 Feb 2025 20:40:52 +0000 (21:40 +0100)] 
docs(pool): add release note about ticket #1014

5 months agofix(pool): reset connection transaction status after failed check
Kanav Kalucha [Tue, 25 Feb 2025 18:28:38 +0000 (10:28 -0800)] 
fix(pool): reset connection transaction status after failed check

Close #1014

5 months agochore: bump psycopg_pool package version to 3.2.6.dev1
Daniele Varrazzo [Fri, 21 Feb 2025 21:28:43 +0000 (22:28 +0100)] 
chore: bump psycopg_pool package version to 3.2.6.dev1

5 months agochore: bump psycopg_pool package version to 3.2.5 pool-3.2.5
Daniele Varrazzo [Fri, 21 Feb 2025 21:23:30 +0000 (22:23 +0100)] 
chore: bump psycopg_pool package version to 3.2.5

5 months agofix(pool): check that there is some connection in the pool before shrinking
Daniele Varrazzo [Fri, 21 Feb 2025 16:27:29 +0000 (17:27 +0100)] 
fix(pool): check that there is some connection in the pool before shrinking

There is a race condition between shrinking the pool and closing an
expired connection which might result in attempting to pop from the
empty _pool deque. Add a check to prevent that.

The bug is not serious as it doesn't compromise the pool working but it causes
noise in the logging.

Close #1001

5 months agochore: drop unused mypy ignore comment
Daniele Varrazzo [Fri, 21 Feb 2025 18:05:36 +0000 (19:05 +0100)] 
chore: drop unused mypy ignore comment

5 months agochore: fix typo
Daniele Varrazzo [Fri, 21 Feb 2025 18:04:46 +0000 (19:04 +0100)] 
chore: fix typo

5 months agostyle: fix up with current version of black
Daniele Varrazzo [Fri, 21 Feb 2025 18:01:36 +0000 (19:01 +0100)] 
style: fix up with current version of black

5 months agochore: bump psycopg_pool package version to 3.2.5.dev1
Daniele Varrazzo [Fri, 21 Feb 2025 18:03:02 +0000 (19:03 +0100)] 
chore: bump psycopg_pool package version to 3.2.5.dev1

8 months agodocs(pool): fix ticket link in news page
Daniele Varrazzo [Sat, 16 Nov 2024 20:40:45 +0000 (21:40 +0100)] 
docs(pool): fix ticket link in news page

8 months agoci: merge all produced artifacts into a single artifact for ease of downloading
Trenton Holmes [Sat, 18 May 2024 20:21:04 +0000 (13:21 -0700)] 
ci: merge all produced artifacts into a single artifact for ease of downloading

8 months agoci: updates action versions and add dependabot to check monthly for updates
Trenton Holmes [Sat, 18 May 2024 01:41:51 +0000 (18:41 -0700)] 
ci: updates action versions and add dependabot to check monthly for updates

8 months agochore: bump psycopg_pool package version to 3.2.4 pool-3.2.4
Daniele Varrazzo [Thu, 14 Nov 2024 13:56:03 +0000 (14:56 +0100)] 
chore: bump psycopg_pool package version to 3.2.4

8 months agotest(crdb): fix or skip tests that now run because libpq 17 is available
Daniele Varrazzo [Sat, 28 Sep 2024 16:01:22 +0000 (18:01 +0200)] 
test(crdb): fix or skip tests that now run because libpq 17 is available

8 months agofix(pool): print a warning if gather times out on del
Daniele Varrazzo [Wed, 13 Nov 2024 13:19:12 +0000 (14:19 +0100)] 
fix(pool): print a warning if gather times out on del

In Python 3.13 something changed on interpreter shutdown and now
stopping threads on __del__ fails.

See #930, #954.

8 months agochore: ignore type error reported by mypy 1.12, 1.13
Daniele Varrazzo [Wed, 30 Oct 2024 13:26:34 +0000 (14:26 +0100)] 
chore: ignore type error reported by mypy 1.12, 1.13

If a generator returns None, the StopIteration.args tuple is empty. The
fact we explicitly checks for it and in that case we return none looks
now an error for Mypy.

I don't see an obvious way around it.

Maybe related to https://github.com/python/mypy/issues/1933 which is an
historical issue (opened in 2016).

Reported in https://github.com/python/mypy/issues/18073

8 months agochore: bump psycopg_pool package version to 3.2.4.dev1
Daniele Varrazzo [Wed, 13 Nov 2024 13:43:35 +0000 (14:43 +0100)] 
chore: bump psycopg_pool package version to 3.2.4.dev1

10 months agochore: bump psycopg_pool package version to 3.2.3 pool-3.2.3
Daniele Varrazzo [Sun, 15 Sep 2024 20:22:01 +0000 (22:22 +0200)] 
chore: bump psycopg_pool package version to 3.2.3

10 months agodocs(pool): note compatibility with Python 3.13
Daniele Varrazzo [Sun, 15 Sep 2024 11:53:37 +0000 (13:53 +0200)] 
docs(pool): note compatibility with Python 3.13

10 months agofix: fix compatibility with numpy 2.0
Daniele Varrazzo [Sun, 23 Jun 2024 11:12:34 +0000 (13:12 +0200)] 
fix: fix compatibility with numpy 2.0

The only meaningful code change is with the bool class, whose type name
changed from `numpy.bool_` to `numpy.bool`. Note that using `bool`
causes a FutureWarning on import for numpy > 1.20, therefore we avoid
testing it (we still successfully test the `bool_` alias).

Other changes are related to tests: certain constant aliases are no more
available, so we skip those tests conditionally to numpy version.

Pin a minimum numpy version, to make sure we test also a numpy v1.
Picking 1.18,  released back in Dec 2019, as it's the first minor
version offering binary packages for Python 3.8. This min dependency will
need to be updated when dropping Python 3.8 support.

10 months agochore: bump typing-extension version
Daniele Varrazzo [Wed, 24 Jul 2024 09:52:46 +0000 (11:52 +0200)] 
chore: bump typing-extension version

Previously requested 4.4 is not compatible with the now requested mypy
version 1.11

10 months agochore: make typing-extension conditional to Pyton < 3.13
Daniele Varrazzo [Mon, 1 Jul 2024 21:50:56 +0000 (23:50 +0200)] 
chore: make typing-extension conditional to Pyton < 3.13

10 months agochore: ignore spelling in html files
Daniele Varrazzo [Tue, 9 Apr 2024 22:33:27 +0000 (00:33 +0200)] 
chore: ignore spelling in html files

These files are generated by cython to display the C code generated...
and are a mess.

10 months agofix: more careful stripping of error prefixes
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).

Close #752.

10 months agochore: fix typo in comment
Daniele Varrazzo [Mon, 27 May 2024 14:20:38 +0000 (16:20 +0200)] 
chore: fix typo in comment

10 months agochore: bump mypy
Daniele Varrazzo [Wed, 24 Jul 2024 09:10:10 +0000 (11:10 +0200)] 
chore: bump mypy

14 months agochore: bump psycopg_pool package version to 3.2.3.dev1
Daniele Varrazzo [Sat, 11 May 2024 15:32:38 +0000 (17:32 +0200)] 
chore: bump psycopg_pool package version to 3.2.3.dev1

14 months agochore: bump psycopg_pool package version to 3.2.2 pool-3.2.2
Daniele Varrazzo [Fri, 10 May 2024 00:05:25 +0000 (02:05 +0200)] 
chore: bump psycopg_pool package version to 3.2.2

14 months agoMerge branch 'pool-empty-query-check' into maint-pool-3.2
Daniele Varrazzo [Fri, 10 May 2024 00:05:10 +0000 (02:05 +0200)] 
Merge branch 'pool-empty-query-check' into maint-pool-3.2

14 months agodocs(pool): mention running an empty query on check in news file
Daniele Varrazzo [Wed, 8 May 2024 16:49:41 +0000 (18:49 +0200)] 
docs(pool): mention running an empty query on check in news file

14 months agorefactor(pool): replace --ping with empty string
Eyal Halpern Shalev [Sat, 4 May 2024 12:57:56 +0000 (15:57 +0300)] 
refactor(pool): replace --ping with empty string

14 months agoperf(pool): replace SELECT 1 with an empty query
Eyal Halpern Shalev [Mon, 15 Apr 2024 23:09:45 +0000 (02:09 +0300)] 
perf(pool): replace SELECT 1 with an empty query

14 months agofix(pool): avoid possible deadlock (until timeout) on pool closing
Daniele Varrazzo [Mon, 6 May 2024 09:21:33 +0000 (11:21 +0200)] 
fix(pool): avoid possible deadlock (until timeout) on pool closing

With the previous change to avoid finding open connections in the pool
(#784), stopping the worker was moved into the critical section. This
can create a deadlock in case a worker is in the process of obtaining a
new connection, because putting it to the pool requires the lock. The
deadlock only last for the default 5s timeout passed to _stop_workers().

Solve the problem by guarding _add_to_pool() to avoid it to try to add
the connection if the pool is closed.

However, refactor the pool closing sequence too and close the workers
and other resources that now out of the state outside the critical
section to keep the operation running under lock to a minimum.

15 months agofix(pool): make sure there are no connection in the pool after close()
Daniele Varrazzo [Wed, 10 Apr 2024 21:58:24 +0000 (23:58 +0200)] 
fix(pool): make sure there are no connection in the pool after close()

The case has been reported in #784. While not easy to reproduce, it
seems that it might be caused by the pool being closed while a worker is
still trying to create a connection, which will be put in the _pool
state after supposedly no other operation should have been performed.

Stop the workers and then empty the pool only after they have stopped to
run.

Also refactor the cleanup of the pool and waiting queue, moving them
to close(). There is no reason why a method called "stop workers" should
empty them, and there is no other code path that use such feature.

Close #784.

15 months agotest(pool): more lenient timeout in reconnect test timings
Daniele Varrazzo [Wed, 10 Apr 2024 22:03:33 +0000 (00:03 +0200)] 
test(pool): more lenient timeout in reconnect test timings

15 months agoMerge branch 'async-to-sync-jobs' into maint-pool-3.2
Daniele Varrazzo [Wed, 10 Apr 2024 21:48:16 +0000 (23:48 +0200)] 
Merge branch 'async-to-sync-jobs' into maint-pool-3.2

15 months agofeat(tools): check last modification times in async_to_sync.py
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.

15 months agofeat(tools): add a -L,--log-level option to async_to_sync.py
Denis Laxalde [Mon, 4 Mar 2024 07:27:14 +0000 (08:27 +0100)] 
feat(tools): add a -L,--log-level option to async_to_sync.py

We'll use DEBUG messages in the next commit.

15 months agofeat(tools): run async_to_sync.py concurrently
Denis Laxalde [Fri, 1 Mar 2024 13:21:35 +0000 (14:21 +0100)] 
feat(tools): run async_to_sync.py concurrently

Multi-processing is used by default (using all available processors),
but can be disabled or limited with the -j/--jobs option.

15 months agostyle: use literals instead of the concatenation operator for long strings
Daniele Varrazzo [Thu, 4 Apr 2024 21:37:57 +0000 (21:37 +0000)] 
style: use literals instead of the concatenation operator for long strings

The reason we were using operators was to stop async_to_sync to generate
a line too long and incur in the flake8 ires.

MR #764 suggests to disable line length check altogether, but we can use
per-file ignore, as there will not be many cases to manage.

17 months agodocs(pool): reorder sections in a way that makes more sense
Daniele Varrazzo [Sun, 18 Feb 2024 00:04:34 +0000 (01:04 +0100)] 
docs(pool): reorder sections in a way that makes more sense

17 months agodocs(pool): add box warning against opening async pools on init
Daniele Varrazzo [Sun, 18 Feb 2024 00:03:20 +0000 (01:03 +0100)] 
docs(pool): add box warning against opening async pools on init

17 months agofix(pool): make opening an async connection pool in the constructor a runtime warning
Daniele Varrazzo [Fri, 16 Feb 2024 13:02:17 +0000 (14:02 +0100)] 
fix(pool): make opening an async connection pool in the constructor a runtime warning

Deprecation warnings are ignored by default and easy to miss.

Close #737.

17 months agoci: skip refcount tests on scheduled jobs
Daniele Varrazzo [Tue, 13 Feb 2024 10:45:27 +0000 (11:45 +0100)] 
ci: skip refcount tests on scheduled jobs

17 months agofix: avoid to create reference loops in datetime adapters
Daniele Varrazzo [Wed, 7 Feb 2024 01:16:06 +0000 (01:16 +0000)] 
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.

17 months agodocs: fix typo in release notes
Daniele Varrazzo [Mon, 5 Feb 2024 16:34:36 +0000 (16:34 +0000)] 
docs: fix typo in release notes

17 months agochore: bump psycopg package version to 3.1.18
Daniele Varrazzo [Sun, 4 Feb 2024 17:42:54 +0000 (17:42 +0000)] 
chore: bump psycopg package version to 3.1.18

17 months agofix(c): drop spurious loop break in pipeline_communicate
Daniele Varrazzo [Fri, 4 Nov 2022 22:17:13 +0000 (23:17 +0100)] 
fix(c): drop spurious loop break in pipeline_communicate

This makes the Python and the C implementation more similar. The
difference was unexpected but apparently harmless. See #431

17 months agochore: update code to master
Daniele Varrazzo [Sun, 4 Feb 2024 14:36:54 +0000 (14:36 +0000)] 
chore: update code to master

18 months agochore: bump psycopg_pool package version to 3.2.2.dev1
Daniele Varrazzo [Sun, 7 Jan 2024 14:47:44 +0000 (15:47 +0100)] 
chore: bump psycopg_pool package version to 3.2.2.dev1

18 months agoci: revert upload action to v3
Daniele Varrazzo [Sun, 7 Jan 2024 11:49:41 +0000 (12:49 +0100)] 
ci: revert upload action to v3

v4 requires to have every uploaded artifact in a separate directory.

- https://github.com/actions/upload-artifact/issues/478
- https://github.com/actions/upload-artifact/blob/main/docs/MIGRATION.md

18 months agochore: bump psycopg_pool package version to 3.2.1 pool-3.2.1
Daniele Varrazzo [Sun, 7 Jan 2024 01:42:03 +0000 (02:42 +0100)] 
chore: bump psycopg_pool package version to 3.2.1

18 months agochore(c): add missing enum entries
Daniele Varrazzo [Sat, 6 Jan 2024 19:37:37 +0000 (20:37 +0100)] 
chore(c): add missing enum entries

18 months agodocs: add note about checking enums and docs on PostgreSQL update
Daniele Varrazzo [Sat, 6 Jan 2024 19:36:56 +0000 (20:36 +0100)] 
docs: add note about checking enums and docs on PostgreSQL update

18 months agoMerge branch 'fix-699' into maint-pool-3.2
Daniele Varrazzo [Sat, 6 Jan 2024 19:48:18 +0000 (20:48 +0100)] 
Merge branch 'fix-699' into maint-pool-3.2

18 months agorefactor: generate conninfo attempts from async counterpart
Daniele Varrazzo [Sat, 6 Jan 2024 17:06:54 +0000 (18:06 +0100)] 
refactor: generate conninfo attempts from async counterpart

18 months agofix: perform multiple attemps if a host name resolve to multiple hosts
Daniele Varrazzo [Sat, 6 Jan 2024 16:24:48 +0000 (17:24 +0100)] 
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.

Close #699.

18 months agorefactor(test): make resolution monkeypatching common fixtures
Daniele Varrazzo [Sat, 6 Jan 2024 16:10:58 +0000 (17:10 +0100)] 
refactor(test): make resolution monkeypatching common fixtures

18 months agorefactor: separate ConnectionInfo object from conninfo module
Daniele Varrazzo [Sat, 6 Jan 2024 14:50:14 +0000 (15:50 +0100)] 
refactor: separate ConnectionInfo object from conninfo module

It was there just because the name is similar, but its purpose is
entirely different.

18 months agochore: align to master
Nick Pope [Tue, 28 Nov 2023 12:46:59 +0000 (12:46 +0000)] 
chore: align to master

The pool branch is diverging unnecessarily from master because so far I
have only cherry picked the changes useful for the pool and compatible
with 3.2.x, but this is creating unnecessary differences and making
cherry-picking harder and harder.

From now on we should use the policy of cherry-picking everything unless
non compatible (not a new feature or a breaking change), similarly to
what we do on the maint-3.1 branch.

18 months agochore: upload github actions dependencies
Daniele Varrazzo [Tue, 2 Jan 2024 03:29:48 +0000 (04:29 +0100)] 
chore: upload github actions dependencies

18 months agoMerge branch 'fix-709' into maint-pool-3.2
Daniele Varrazzo [Sat, 6 Jan 2024 12:09:04 +0000 (13:09 +0100)] 
Merge branch 'fix-709' into maint-pool-3.2

18 months agorefactor(pool): rename ConnectionAttempt as AttemptWithBackoff 711/head
Daniele Varrazzo [Fri, 29 Dec 2023 23:49:28 +0000 (00:49 +0100)] 
refactor(pool): rename ConnectionAttempt as AttemptWithBackoff

This class implements the backoff + jitter policy and is now used to
repeat checks too.

18 months agofix(pool): use an exponential backoff to separate failing checks
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.

See also #709

18 months agofix(pool): respect timeout on getconn() when the check function fails
Daniele Varrazzo [Fri, 29 Dec 2023 13:15:07 +0000 (14:15 +0100)] 
fix(pool): respect timeout on getconn() when the check function fails

Close #709.

18 months agoMerge branch 'fix-308-pool-3.2' into maint-pool-3.2
Daniele Varrazzo [Sat, 6 Jan 2024 12:02:19 +0000 (13:02 +0100)] 
Merge branch 'fix-308-pool-3.2' into maint-pool-3.2

18 months agorefactor(pool): avoid constructor overloading by using generic default
Daniele Varrazzo [Wed, 3 Jan 2024 01:32:28 +0000 (02:32 +0100)] 
refactor(pool): avoid constructor overloading by using generic default

18 months agorefactor: drop overloading of the Connection.connect() function
Daniele Varrazzo [Wed, 3 Jan 2024 01:14:46 +0000 (02:14 +0100)] 
refactor: drop overloading of the Connection.connect() function

The default for the Row TypeVar makes it redundant.

18 months agorefactor: use Self to represent the return from `BaseConnection._connect_gen()`
Daniele Varrazzo [Wed, 3 Jan 2024 00:59:30 +0000 (01:59 +0100)] 
refactor: use Self to represent the return from `BaseConnection._connect_gen()`

18 months agofix: define the Row TypeVar as defaulting to TupleRow
Daniele Varrazzo [Wed, 3 Jan 2024 00:44:22 +0000 (01:44 +0100)] 
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.

Close #308

18 months agorefactor: use typing.Self
Daniele Varrazzo [Sat, 30 Dec 2023 00:30:39 +0000 (01:30 +0100)] 
refactor: use typing.Self

The object seems available for all the supported Python version and
should avoid problems with PyRight (see #708).

It is not a solution for #308 because we cannot use `Self[Row]`.

18 months agorefactor: use TypeVar from typing_extension
Daniele Varrazzo [Wed, 3 Jan 2024 00:33:35 +0000 (01:33 +0100)] 
refactor: use TypeVar from typing_extension

This includes the default parameter, which should fix the problem of the
awkward definition of Row defaulting to TupleRow.

19 months agorefactor: use typing.Self
Daniele Varrazzo [Sat, 30 Dec 2023 00:30:39 +0000 (01:30 +0100)] 
refactor: use typing.Self

The object seems available for all the supported Python version and
should avoid problems with PyRight (see #708).

It is not a solution for #308 because we cannot use `Self[Row]`.

19 months agochore: bump psycopg_pool package version to 3.2.1.dev1
Daniele Varrazzo [Fri, 29 Dec 2023 13:11:38 +0000 (14:11 +0100)] 
chore: bump psycopg_pool package version to 3.2.1.dev1

20 months agochore: fix mypy >= 1.7 warning in tests
Daniele Varrazzo [Sat, 11 Nov 2023 15:30:55 +0000 (15:30 +0000)] 
chore: fix mypy >= 1.7 warning in tests

20 months agoci: test psycopg pool package with released a psycopg version
Daniele Varrazzo [Sat, 11 Nov 2023 16:50:42 +0000 (16:50 +0000)] 
ci: test psycopg pool package with released a psycopg version

20 months agotest: allow to run pytest -m pool with psycopg 3.1 imported
Daniele Varrazzo [Sat, 11 Nov 2023 16:47:35 +0000 (16:47 +0000)] 
test: allow to run pytest -m pool with psycopg 3.1 imported

This allows to test psycopg pool 3.2 tests with psycopg 3.1 installed.

20 months agochore: bump psycopg_pool package version to 3.2.0 pool-3.2.0
Daniele Varrazzo [Sat, 11 Nov 2023 14:59:49 +0000 (14:59 +0000)] 
chore: bump psycopg_pool package version to 3.2.0

20 months agofix(bump_version): fix bumping minor version with dev releases
Daniele Varrazzo [Sat, 11 Nov 2023 14:59:09 +0000 (14:59 +0000)] 
fix(bump_version): fix bumping minor version with dev releases

20 months agochore(macos): build images with more recent Python versions
Daniele Varrazzo [Thu, 2 Nov 2023 09:25:18 +0000 (10:25 +0100)] 
chore(macos): build images with more recent Python versions

21 months agoMerge pull request #670 from psycopg/fix-667
Daniele Varrazzo [Tue, 24 Oct 2023 18:14:59 +0000 (19:14 +0100)] 
Merge pull request #670 from psycopg/fix-667

Handle gracefully EINTR on signals instead of raising InterruptedError

21 months agofix: retry automatically syscall in wait_c if it fails with EINTR 670/head
Daniele Varrazzo [Tue, 24 Oct 2023 09:19:36 +0000 (11:19 +0200)] 
fix: retry automatically syscall in wait_c if it fails with EINTR

Fix #667

21 months agotest: add test to generate an EINTR in wait_c
Daniele Varrazzo [Tue, 24 Oct 2023 08:50:40 +0000 (10:50 +0200)] 
test: add test to generate an EINTR in wait_c

21 months agoMark test_identify_closure as timing-sensitive
Martin Weinelt [Mon, 23 Oct 2023 22:54:18 +0000 (00:54 +0200)] 
Mark test_identify_closure as timing-sensitive

```
____________________________ test_identify_closure _____________________________

conn_cls = <class 'psycopg.Connection'>, dsn = 'host=127.0.0.1 user=psycopg'

    @pytest.mark.crdb_skip("pg_terminate_backend")
    @pytest.mark.slow
    def test_identify_closure(conn_cls, dsn):
        def closer():
            time.sleep(0.2)
            conn2.execute("select pg_terminate_backend(%s)", [conn.pgconn.backend_pid])

        conn = conn_cls.connect(dsn)
        conn2 = conn_cls.connect(dsn)
        try:
            t = threading.Thread(target=closer)
            t.start()
            t0 = time.time()
            try:
                with pytest.raises(psycopg.OperationalError):
                    conn.execute("select pg_sleep(1.0)")
                t1 = time.time()
>               assert 0.2 < t1 - t0 < 0.4
E               assert 0.2 < (1697715164.8614173 - 1697715164.6617775)

tests/test_concurrency.py:231: AssertionError
```

21 months agochore: use AnyIO 4.0+ in tests dependencies
Denis Laxalde [Wed, 18 Oct 2023 08:35:50 +0000 (10:35 +0200)] 
chore: use AnyIO 4.0+ in tests dependencies

We set the 'loop_factory' asyncio option for parametrizing the
anyio_backend() fixture as anyio 4.0 has replaced the 'policy' option by
'loop_factory'.

In tests/pool/test_pool_async_noasyncio.py, we previously used
the anyio_backend_options fixture to retrieve the loop policy; now we
build it directly. This could be improved by using the loop_factory, but
only from Python 3.11 with an asyncio.Runner().

21 months agorefactor(pool): more logical ordering for kwargs
Daniele Varrazzo [Sat, 14 Oct 2023 07:59:57 +0000 (09:59 +0200)] 
refactor(pool): more logical ordering for kwargs

- conn construction params (class, kwargs, the class affects the pool
  type annotations so first is better);
- sizing (documented as an important parameter for the pool);
- open?
- callbacks (in the order they are used);
- name;
- other details more unlikely to be touched.

The order is the same in docs and code.

21 months agoMerge branch 'pool-getconn-safe'
Daniele Varrazzo [Sat, 14 Oct 2023 07:45:52 +0000 (09:45 +0200)] 
Merge branch 'pool-getconn-safe'

21 months agodocs(pool): document check callback, drop previous recipes and rants 658/head
Daniele Varrazzo [Sat, 7 Oct 2023 02:16:43 +0000 (04:16 +0200)] 
docs(pool): document check callback, drop previous recipes and rants

21 months agotest(pool): add tests to verify check on getconn's behaviour
Daniele Varrazzo [Fri, 6 Oct 2023 16:31:52 +0000 (18:31 +0200)] 
test(pool): add tests to verify check on getconn's behaviour

21 months agofix(pool): clean up logging in getconn check
Daniele Varrazzo [Fri, 6 Oct 2023 16:30:18 +0000 (18:30 +0200)] 
fix(pool): clean up logging in getconn check

If a check callback is set, assume that failed checks on getconn are
just part of normal operative life: don't consider them warnings.

21 months agofeat(pool): add `check` connection parameter
Daniele Varrazzo [Fri, 6 Oct 2023 13:15:04 +0000 (15:15 +0200)] 
feat(pool): add `check` connection parameter

Allow to specify a callback to call on getconn and discard the
connection if not in working state.

21 months agofeat(pool): add `check_connection()` method
Daniele Varrazzo [Fri, 6 Oct 2023 13:13:39 +0000 (15:13 +0200)] 
feat(pool): add `check_connection()` method

The method is public, will be documented as available to use as check
parameter, but also used internally by the `check()` method.

21 months agorefactor(pool): introduce a loop in getconn to allow connection check
Daniele Varrazzo [Fri, 6 Oct 2023 11:00:41 +0000 (13:00 +0200)] 
refactor(pool): introduce a loop in getconn to allow connection check

21 months agoMerge branch 'pool-warn-implicit-open'
Daniele Varrazzo [Sat, 14 Oct 2023 07:40:00 +0000 (09:40 +0200)] 
Merge branch 'pool-warn-implicit-open'

21 months agodocs(pool): warn about future behaviour changes of open on init 659/head
Daniele Varrazzo [Fri, 13 Oct 2023 23:51:11 +0000 (01:51 +0200)] 
docs(pool): warn about future behaviour changes of open on init

21 months agofeat(pool): raise a warning if async pools are open in the constructor
Daniele Varrazzo [Sun, 8 Oct 2023 18:43:47 +0000 (20:43 +0200)] 
feat(pool): raise a warning if async pools are open in the constructor