]> git.ipfire.org Git - thirdparty/psycopg.git/commit
fix: finish the PGconn upon connection failure 570/head
authorDenis Laxalde <denis.laxalde@dalibo.com>
Fri, 19 May 2023 07:06:55 +0000 (09:06 +0200)
committerDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 13 Jun 2023 11:19:30 +0000 (13:19 +0200)
commite70010fa2626291201b76112a0f4593dcd3d92e3
tree26b9f03a123e5eb0b54755fc6dfe3184ef787986
parent84cb324b267d2b5ae92960dcc64576bdec22889d
fix: finish the PGconn upon connection failure

Attaching the non-finished PGconn to exceptions raised in connect() is
causing problem, as described in issue #565, because the PGconn might
not get finished soon enough in application code and the socket would
remain open.

On the other hand, just removing the pgconn attribute from Error would
be a breaking change and we'd loose the inspection features introduced
in commit 9220293dc023b757f2a57702c14b1460ff8f25b0.

As an alternative, we define a new PGconn implementation that is
error-specific: it captures all attributes of the original PGconn and
fails upon other operations (methods call). Some attributes have a
default value since they are not available in old PostgreSQL versions.

Finally, the (real) PGconn is finished before raising exception in
generators.connect().
docs/api/errors.rst
docs/news.rst
psycopg/psycopg/errors.py
psycopg/psycopg/generators.py
psycopg_c/psycopg_c/_psycopg/generators.pyx
tests/test_errors.py
tests/test_generators.py