From de848f64fa3c423b80af36c37733fdfbfc2ab7ec Mon Sep 17 00:00:00 2001 From: Diogo Biazus Date: Tue, 16 Feb 2016 23:01:03 -0500 Subject: [PATCH] Return the results from withResource function before applying the respond continuation. This ensures that the pool resource is freed as soon as the database operation is complete --- src/PostgREST/Main.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/PostgREST/Main.hs b/src/PostgREST/Main.hs index 3701e36a7..8e6506e1a 100644 --- a/src/PostgREST/Main.hs +++ b/src/PostgREST/Main.hs @@ -97,8 +97,9 @@ main = do body <- strictRequestBody req let handleReq = H.run $ inTransaction ReadCommitted (runWithClaims conf time (app dbStructure conf body) req) - withResource pool $ \case - Left err -> respond $ errResponse HT.status500 (cs . show $ err) + res <- withResource pool $ \case + Left err -> return $ errResponse HT.status500 (cs . show $ err) Right c -> do resOrError <- handleReq c - either (respond . pgErrResponse) respond resOrError + either (return . pgErrResponse) return resOrError + respond res