pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dietmar May <dcmay@dmis.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: pgsql-interfaces@postgresql.org
Subject: Re: Race condition with libpq
Date: Mon, 26 May 2003 14:25:38 -0400
Message-ID: <00ab01c323b4$3516d4c0$fb02a8c0@muskrat> (raw)
In-Reply-To: <2388.1053968719@sss.pgh.pa.us>

Hi Tom,

> > So, why can't the server-side code that closes the connection
> > release any resources associated with that connection before
> > the socket is closed? It seems that doing so could fix this
> > problem quite cleanly.
>
> How would that help?  The client isn't waiting around for it,
> because it already closed its socket.

Ah-ha! Your comments are really helping to narrow down the problem. Maybe
we're getting to a solution here.

Perhaps instead of simply shutting down the connection, PQfinish() could
request the server to close the connection, and block until the connection
is closed. The server would first clean up any resources associated with the
connection, and then close the connection. The client code would then be
sure that it no longer has any resources in use when the socket shuts down.

This would take care of the race condition, not only for the case of DROP
DATABASE, but perhaps for other cases as well. After all, there is really no
guaranteed order of process execution, nor of process execution scheduling,
nor of the priority at which various processes are running.

In theory, a whole host of other similar race condition failures could occur
due to the current design of connection closure. By changing this operation
slightly, the possibility of these race conditions can be eliminated.

The current behavior could perhaps still be supported using an extra boolean
parameter to PQfinish(), in case someone doesn't need to ensure that
server-side resources are released before returning from PQfinish().

Regards,
Dietmar




view thread (7+ messages)

Message-ID: <00ab01c323b4$3516d4c0$fb02a8c0@muskrat>
Permalink:  ../00ab01c323b4$3516d4c0$fb02a8c0@muskrat/
Also on:    postgresql.org/message-id/00ab01c323b4$3516d4c0$fb02a8c0@muskrat

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-interfaces@postgresql.org
  Cc: dcmay@dmis.com, tgl@sss.pgh.pa.us
  Subject: Re: Race condition with libpq
  In-Reply-To: <00ab01c323b4$3516d4c0$fb02a8c0@muskrat>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox