Skip to content

Commit 78bb3a9

Browse files
committed
Ensure connections are strictly finalized.
Currently, the connection is subject to finalization by the Haskell Garbage collector. In the face of a large heap these finalizers may not be run. Forcing resource finalization ensures deterministic resource usage.
1 parent a1f238e commit 78bb3a9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

Database/HDBC/PostgreSQL/Connection.hsc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ mkConn auto_transaction args conn = withConn conn $
7979
serverver <- pqserverVersion cconn
8080
let clientver = #{const_str PG_VERSION}
8181
let rconn = Impl.Connection {
82-
Impl.disconnect = fdisconnect children,
82+
Impl.disconnect = fdisconnect conn children,
8383
Impl.begin = if auto_transaction
8484
then return ()
8585
else begin_transaction conn children,
@@ -170,8 +170,11 @@ fdescribeSchemaTable o cl maybeSchema table =
170170
desccol x =
171171
error $ "Got unexpected result from pg_attribute: " ++ show x
172172

173-
fdisconnect :: ChildList -> IO ()
174-
fdisconnect = closeAllChildren
173+
fdisconnect :: Conn -> ChildList -> IO ()
174+
fdisconnect (lock, fptr) childList = do
175+
closeAllChildren childList
176+
modifyMVar_ lock $ \_ ->
177+
finalizeForeignPtr fptr
175178

176179
foreign import ccall safe "libpq-fe.h PQconnectdb"
177180
pqconnectdb :: CString -> IO (Ptr CConn)

0 commit comments

Comments
 (0)