Skip to content
Snippets Groups Projects
Commit f339d7f8 authored by Stephen R. van den Berg's avatar Stephen R. van den Berg
Browse files

pgsql: Kludge around clone race in Pike core.

As reported by Jeff Hungerford:

When there is:
- No connection at present.
- Two or more threads try to open an initial connection to the database
  simultaneously.

You can trigger this:

Attempting to clone an unfinished program
/usr/local/pike/8.0.175/lib/modules/Sql.pmod/Sql.pike:342:
    Sql.Sql()->create("localhost:5432","foo","bar","CENSORED",UNDEFINED)

This could be caused by a race in the Pike-core class-cloning code which
is not racefree when two threads try to instantiate the same object
at roughly the same instant.

This patch attempts a workaround to detect the race and loop until
it finishes without problems.  It would be better if this could be
fixed in the Pike-core.
parent d483c054
No related branches found
No related tags found
No related merge requests found
......@@ -217,7 +217,15 @@ protected void create(void|string host, void|string database,
if(!_port)
_port = PGSQL_DEFAULT_PORT;
.pgsql_util.register_backend();
// FIXME Looks like a bug in the cloning of an object
// If we do not loop here, and this function is called in two threads
// simultaneously, *and* the .pgsql_util class has not been instantiated
// yet, then Pike can throw an "Attempting to clone an unfinished program"
// error.
while(catch(.pgsql_util.register_backend())) // Placate race in cloning
sleep(0); // Yield
_shortmux=Thread.Mutex();
reconnect();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment