You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using pool to manage a series of PostgreSQL connections (via postgresql-simple), I've found that idle connections are not being reaped. After doing some digging, it appears that the reaper thread is being killed almost immediately, which I've linked to the execution of the finaliser attached to the internal finIORef. I've no doubt that this is an issue with my code and not pool, but was wondering if I might find some help here. While I've not managed to produce a minimal reproducing test case, I have details about what I'm doing:
I'm wrapping the pool in a newtype, as in newtype MyPool = MyPool (Pool PG.Connection) and building one with fmap viz.
The above function results in the following core. To my inexperienced eyes, it doesn't suggest any cheeky unpacking/losing of the IORef by GHC (which to my inexperienced brain is what would trigger a GHC and subsequent finalizer running, no?):
The created pool is being used to run a transformer stack, as in runPostgreSQL pool, and is working just fine in every other regard, so it seems like the fin is the only part of the structure being GC'd (again, assuming that this is the cause of the finaliser's running).
To be clear, removing the call to mkWeakIORef causes the reaper to work correctly. Furthermore, the local pool finalizers can be left in place without affecting its working. Lastly, using addFinalizer from System.Mem.Weak (as was done in a previous version of this library, I believe) does not help either (again, perhaps it was stupid to assume it would).
Thanks in advance for any advice and apologies for not providing a minimal working example; I am struggling to find out exactly what I'm doing that's causing this. If there is any other information I can provide in the mean time I am happy to oblige to try and crack this.
The text was updated successfully, but these errors were encountered:
When using
pool
to manage a series of PostgreSQL connections (viapostgresql-simple
), I've found that idle connections are not being reaped. After doing some digging, it appears that the reaper thread is being killed almost immediately, which I've linked to the execution of the finaliser attached to the internalfin
IORef
. I've no doubt that this is an issue with my code and notpool
, but was wondering if I might find some help here. While I've not managed to produce a minimal reproducing test case, I have details about what I'm doing:newtype
, as innewtype MyPool = MyPool (Pool PG.Connection)
and building one withfmap
viz.IORef
by GHC (which to my inexperienced brain is what would trigger a GHC and subsequent finalizer running, no?):runPostgreSQL pool
, and is working just fine in every other regard, so it seems like thefin
is the only part of the structure being GC'd (again, assuming that this is the cause of the finaliser's running).mkWeakIORef
causes the reaper to work correctly. Furthermore, the local pool finalizers can be left in place without affecting its working. Lastly, usingaddFinalizer
fromSystem.Mem.Weak
(as was done in a previous version of this library, I believe) does not help either (again, perhaps it was stupid to assume it would).Thanks in advance for any advice and apologies for not providing a minimal working example; I am struggling to find out exactly what I'm doing that's causing this. If there is any other information I can provide in the mean time I am happy to oblige to try and crack this.
The text was updated successfully, but these errors were encountered: