Pike 8.0: Sql.pgsql objects don't get garbage collected?

Jeff Hungerford <[email protected]>
Newsgroups gmane.comp.lang.pike.user
Message-ID <[email protected]>
Greetings,

I was testing out Roxen 6 on Pike 8, and I noticed a constantly increasing count of idle
connections to a Postgres database, while Roxen thought there were only a couple of connections.

I did a bit of testing, and it appears that a Sql.pgsql object does not get garbage collected
once all references are lost, and it stays active.

For a quick first test, I opened a database connection, and set a watch on the master_sql object,
then ran a gc.  The debug output showed a reference to the master_sql object during the run.


The test:

-=-=-=-
int main()
{
  Debug.gc_set_watch(Sql.Sql("pgsql://hungerf3@localhost:5432/hungerf3")->master_sql);
  gc();
}
-=-=-=-

The output:

-=-=-=-
## Watching thing 0x25b7770.
## Doing gc while watching for 1 things.
## Watched thing 0x25b7770 with 1 refs found in gc_mark_external() in pass 100.
marker at 0x241fa60: flags=0x1000000 refs=0 weak=0 xrefs=0 saved=-1 frame=(nil)
## Watched thing 0x25b7770 with 1 refs found in gc_is_referenced() in pass 200.
marker at 0x241fa60: flags=0x1080000 refs=0 weak=0 xrefs=1 saved=-1 frame=(nil)
## Watched thing 0x25b7770 with 1 refs found in gc_mark() in pass 200.
marker at 0x241fa60: flags=0x10c0000 refs=0 weak=0 xrefs=1 saved=-1 frame=(nil)
## Exiting gc and resetting watches for 1 things.
-=-=-=-

So the Sql.pgsql instance inside the Sql.Sql object never got garbage collected.

I did a bit more testing, with a weak reference to the master_sql object inside the
Sql.Sql object I was destroying.

Debug.locate_references found an active reference inside of pgsql_util:

**Function connectloop at /usr/local/pike/8.0.155/lib/modules/Sql.pmod/pgsql_util.pmod:365

Pike.identify_cycle found the following cycle:

({ /* 4 elements */
    pgsql(hungerf3@localhost:5432/hungerf3,11,0),
    Sql.pgsql,
    Pike.Backend(1),
    Stdio.File("socket", "localhost:5432", 777 /* fd=11 */)
})


My guess would be that the local backend inside of pgsql_util.pmod is holding on to the
connection object, and so it is not being garbage collected.

Has anyone else run into this?  I saw it on both Linux and FreeBSD with Pike 8.0.155.
Both were using AMD64 machine code, and talking to a PostgreSQL 9.5 database.

-Jeff
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.