summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2025-03-24 21:55:39 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2025-03-27 20:21:08 +0100
commit03f37ea3a7e77eb79381ca41c6612c38bd5727d9 (patch)
tree0e0f3f6765dd2ee39f099f6c00b86dfd73ada904
parent59a2580c4cecb4acc53b812dc5fc8df091bf8516 (diff)
ICE: fix deadlock when creating session without STUN/TURN
-rw-r--r--src/Erebos/ICE.chs8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Erebos/ICE.chs b/src/Erebos/ICE.chs
index 2a6c174..6f61451 100644
--- a/src/Erebos/ICE.chs
+++ b/src/Erebos/ICE.chs
@@ -19,7 +19,7 @@ module Erebos.ICE (
) where
import Control.Arrow
-import Control.Concurrent.MVar
+import Control.Concurrent
import Control.Monad
import Control.Monad.Except
import Control.Monad.Identity
@@ -143,7 +143,11 @@ iceCreateConfig stun turn =
iceCreateSession :: IceConfig -> IceSessionRole -> (IceSession -> IO ()) -> IO IceSession
iceCreateSession icfg@(IceConfig fcfg) role cb = do
rec sptr <- newStablePtr sess
- cbptr <- newStablePtr $ cb sess
+ cbptr <- newStablePtr $ do
+ -- The callback may be called directly from pj_ice_strans_create or later
+ -- from a different thread; make sure we use a different thread here
+ -- to avoid deadlock on accessing 'sess'.
+ forkIO $ cb sess
sess <- IceSession
<$> (withForeignPtr fcfg $ \cfg ->
{#call ice_create #} (castPtr cfg) (fromIntegral $ fromEnum role) (castStablePtrToPtr sptr) (castStablePtrToPtr cbptr)