From 4fe124d2169466f36ae2fb6f0f30e29cc92d3b22 Mon Sep 17 00:00:00 2001 From: Harendra Kumar Date: Wed, 13 May 2026 11:23:33 +0530 Subject: [PATCH] Fix race condition in sendExceptionToDriver We were ringing the doorbell too early even before we sent the message, so the doorbell could go waste if the reader woke up before the message was sent. --- src/Streamly/Internal/Data/Fold/Channel/Type.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Streamly/Internal/Data/Fold/Channel/Type.hs b/src/Streamly/Internal/Data/Fold/Channel/Type.hs index e04146a09b..19d1dea2ba 100644 --- a/src/Streamly/Internal/Data/Fold/Channel/Type.hs +++ b/src/Streamly/Internal/Data/Fold/Channel/Type.hs @@ -314,8 +314,9 @@ sendExceptionToDriver :: Channel m a b -> SomeException -> IO () sendExceptionToDriver sv e = do tid <- myThreadId writeIORef (closedForInput sv) True - void $ tryPutMVar (inputSpaceDoorBell sv) () + -- Should ring the doorbell after sending the message void $ sendToDriver sv (FoldException tid e) + void $ tryPutMVar (inputSpaceDoorBell sv) () data FromSVarState m a b = FromSVarRead (Channel m a b)