Re: psycopg2 (async) socket timeout

From: Marko Kreen <markokr(at)gmail(dot)com>
To: Danny Milosavljevic <danny(dot)milo(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: psycopg2 (async) socket timeout
Date: 2011-02-15 05:39:25
Message-ID: AANLkTinw9xUnsnpX5AmzMSb=KpktXTGsaNknONJ9HPWB@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Thu, Feb 3, 2011 at 10:04 PM, Danny Milosavljevic
<danny(dot)milo(at)gmail(dot)com> wrote:
> is it possible to specify the timeout for the socket underlying a connection?
>
> Alternatively, since I'm using the async interface anyway, is it
> possible proactively cancel a query that is "stuck" since the TCP
> connection to the database is down?
>
> So the specific case is:
> - connect to the postgres database using psycopg2 while network is up
> - run some queries, get the results fine etc
> - send a query
> - the network goes down before the result to this last query has been received
> - neither a result nor an error callback gets called - as far as I can
> see (using txpostgres.ConnectionPool)
>
> What's the proper way to deal with that?

TCP keepalive. By default the timeouts are quite high,
but they are tunable.

libpq supports keepalive tuning since 9.0, on older libpq
you can do it yourself:

https://github.com/markokr/skytools/blob/master/python/skytools/psycopgwrapper.py#L153

--
marko

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Federico Di Gregorio 2011-02-15 08:26:51 Re: RELEASE: psycopg 2.4 beta 2
Previous Message Daniele Varrazzo 2011-02-15 01:30:50 Re: psycopg2 (async) socket timeout