Skip to content

Commit 6a8b7d8

Browse files
committed
fix: Listener retries should be performed with exceptions unmasked
forkFinally calls error handler with exceptions masked. Our handleFinally does not restore exception state before calling retryingListener so after first error the whole listener is running with exceptions masked. This patch ensures handleFinally is run with exceptions unmasked.
1 parent 6a48f90 commit 6a8b7d8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/PostgREST/Listener.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ retryingListen appState = do
4444
unless (delay == maxDelay) $
4545
AppState.putNextListenerDelay appState (delay * 2)
4646
retryingListen appState
47+
48+
withHandler action = mask $ \restore -> forkIO $ try (restore action) >>= restore . handleFinally
4749

4850
-- forkFinally allows to detect if the thread dies
49-
void . flip forkFinally handleFinally $ do
51+
void . withHandler $ do
5052
bracket (SQL.acquire $ toUtf8 (Config.addTargetSessionAttrs $ Config.addFallbackAppName prettyVersion configDbUri)) (`whenRight` releaseConnection) $ \dbOrError -> do
5153
case dbOrError of
5254
Right db -> do

0 commit comments

Comments
 (0)