Postgres and blocked poll

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Postgres and blocked poll

Holger Freyther
Hi Paolo,

I have one more issue with the Postgres DBI driver. In case of the VPN
vanishing (or suspend/resume my laptop) the next database query will call
PQgetResult which will block in poll forever.

According to the Postgres documentation one can get the socket from the
connection, use the PQconsumeInput to make PQ read it and there is something
like PQisbusy.

Now the question is how to integrate this. Whenever executing a query I could
greate a FileDescriptor, wait until it is readable, call PQconsumeInput..

[
   PQisBusy..
] whileFalse: [
   (FileDescriptor on: connection socket) ensureReadable.
   PQConsumeInput..
].

Does this sound okay? This would just leave the issue when connecting.

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Postgres and blocked poll

Paolo Bonzini-2
On 04/21/2011 12:15 PM, Holger Hans Peter Freyther wrote:

> Hi Paolo,
>
> I have one more issue with the Postgres DBI driver. In case of the VPN
> vanishing (or suspend/resume my laptop) the next database query will call
> PQgetResult which will block in poll forever.
>
> According to the Postgres documentation one can get the socket from the
> connection, use the PQconsumeInput to make PQ read it and there is something
> like PQisbusy.
>
> Now the question is how to integrate this. Whenever executing a query I could
> greate a FileDescriptor, wait until it is readable, call PQconsumeInput..
>
> [
>     PQisBusy..
> ] whileFalse: [
>     (FileDescriptor on: connection socket) ensureReadable.
>     PQConsumeInput..
> ].
>
> Does this sound okay?

Yes, it does, though it should be a SocketImpl, not a FileDescriptor.
Also, you need to make it non-finalized, or alternatively you can store
it in an instance variable (preferred, probably).  That would be

...
    socket := Sockets.SocketImpl on: connection pqSocket
...
    [
        socket ensureReadable.
        connection consumeInput; isBusy
    ] whileTrue

Nice API! :)

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/help-smalltalk