Skip to content

Commit 2948f0f

Browse files
committed
only run the respond function in a bound thread
1 parent 42baea0 commit 2948f0f

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

kore-rpc-types/src/Kore/JsonRpc/Server.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Kore.JsonRpc.Server (
1414
JsonRpcHandler (..),
1515
) where
1616

17-
import Control.Concurrent (forkIO, forkOS, throwTo)
17+
import Control.Concurrent (forkIO, runInBoundThread, throwTo)
1818
import Control.Concurrent.STM.TChan (newTChan, readTChan, writeTChan)
1919
import Control.Exception (Exception (fromException), catch, mask, throw)
2020
import Control.Monad (forever)
@@ -135,7 +135,10 @@ srv runBound respond handlers = do
135135
sendResponses r = Log.runNoLoggingT $ flip runReaderT rpcSession $ sendBatchResponse r
136136

137137
respondTo :: Request -> IO (Maybe Response)
138-
respondTo req = buildResponse (respond req) req
138+
respondTo req
139+
| runBound = runInBoundThread $ buildResponse (respond req) req
140+
| otherwise = buildResponse (respond req) req
141+
-- workers should run in bound threads (to secure foreign calls) when flagged
139142

140143
cancelReq :: ErrorObj -> BatchRequest -> IO ()
141144
cancelReq err = \case
@@ -174,8 +177,7 @@ srv runBound respond handlers = do
174177
restore (thing a) `catch` catchesHandler a
175178

176179
liftIO $
177-
-- workers should run in bound threads (to secure foreign calls) when flagged
178-
(if runBound then forkOS else forkIO) $
180+
forkIO $
179181
forever $
180182
bracketOnReqException
181183
(atomically $ readTChan reqQueue)

0 commit comments

Comments
 (0)