Closed staab closed 4 years ago
This might be a result of not marking stuff properly for gc. See fced73a for a possible solution. We might also need to either use refcounts or store references to active Results on the corresponding Connection, then when the Connection gets gc'd close the active results first.
To re-state in @bakpakin's words: an open requests counter on the connection could do that. The request object finalizer would decrement the counter on the connection, and if it was 0 and the connection was closed, only then actually clean up the connection. The connection finalizer would similarly decrement the counter, and only Pq free or whatever the connection if the counter was 0.
As of 1.6.0, if two values are freed in the same GC cycle, they will be freed in the reverse order they are allocated (LIFO). This is not guaranteed by the API, but by the current implementation. It also means we don't need to mess with counters or the like right now - the finalizer for a connection will always run after the finalizer for a request if the connection is allocated first (which it must be, as it is used to create the request).
Cool, so I think the basic structure of core.c is good for now then. The above segfault obviously isn't related to the gc issue, and I haven't hit it in a while, so closing this for now.