Re: Error during garbage collection after calling isready() on a closed connection

Federico Di Gregorio <fog-NGVKUo/i/[email protected]>
Newsgroups gmane.comp.python.db.psycopg.devel
Organization initd.org
Message-ID <[email protected]>
Il giorno ven, 09/01/2009 alle 17.13 +0200, Brian Sutherland ha scritto:
> Hi,
> 
> Attached is an example script of a nasty little bug I found. It looks
> like calling .isready() on a server closed connection causes an error
> during the next garbage collection. That can cause all sorts of havoc on
> a python process.
> 
> I found it in version 2.5.1 and verified that it's still there in 2.0.8.

Hi,

cursor.isready() now raise an exception if the internal call to libpq
reports problems. This is probably now _exactly_ what you want because
the first call to isready() after the disconnection results in a notice
(correctly appended to connections notices) and not in an error. An
error will be raised on any successive call that try to use the now
dropped connection.

This fix is available from bzr repository.

This seems correct to me, because the cursor is ready and is reading
some "cached" data (the disconnection message) that was sent by the
server just before dropping the connection.

Technical note: even after consuming the input and checking the
connection (PQconsumeInput and PQisBusy calls), the connection is still
CONNECTION_OK so on the first call to isready() after the server restart
we don't have any way to understand what's happening except for parsing
the notice (unrealiable IMHO).

federico

-- 
Federico Di Gregorio                         http://people.initd.org/fog
Debian GNU/Linux Developer                                [email protected]
INIT.D Developer                                           fog-NGVKUo/i/[email protected]
 And anyone who yells "fork" deserves to get one stuck in them.
                                                          -- Dan Winship

_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg
signature.asc (application/pgp-signature, 197 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEABECAAYFAklo5BgACgkQvcCgrgZGjeuI+wCgtiJrPg7hNKSlIS+BXMzke6Pg
HzIAoKBzBprT2XwNnz4LZK4BRfvtIgtb
=lnqb
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.