-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
More consistent client-side exceptions
- Loading branch information
Showing
19 changed files
with
160 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{-# OPTIONS_GHC -Wno-redundant-constraints #-} | ||
|
||
module Network.GRPC.Util.Concurrency ( | ||
-- * @Control.Concurrent@ | ||
module ReexportConcurrent | ||
, forkIO | ||
, forkIOWithUnmask | ||
-- * @Control.Concurrent.Async@ | ||
, module ReexportAsync | ||
, withAsync | ||
-- * @Control.Concurrent.STM@ | ||
, module ReexportSTM | ||
, atomically | ||
, STMException(..) | ||
) where | ||
|
||
import Control.Exception | ||
import GHC.Stack | ||
|
||
import Control.Concurrent as ReexportConcurrent hiding (forkIO, forkIOWithUnmask) | ||
import Control.Concurrent.Async as ReexportAsync hiding (withAsync) | ||
import Control.Concurrent.STM as ReexportSTM hiding (atomically) | ||
|
||
import Control.Concurrent qualified as Concurrent | ||
import Control.Concurrent.Async qualified as Async | ||
import Control.Concurrent.STM qualified as STM | ||
|
||
{------------------------------------------------------------------------------- | ||
Wrap thread spawning | ||
-------------------------------------------------------------------------------} | ||
|
||
forkIO :: HasCallStack => IO () -> IO ThreadId | ||
forkIO = Concurrent.forkIO . wrapThreadBody | ||
|
||
forkIOWithUnmask :: | ||
HasCallStack | ||
=> ((forall a. IO a -> IO a) -> IO ()) | ||
-> IO ThreadId | ||
forkIOWithUnmask k = Concurrent.forkIOWithUnmask $ \unmask -> | ||
wrapThreadBody (k unmask) | ||
|
||
withAsync :: HasCallStack => IO a -> (Async a -> IO b) -> IO b | ||
withAsync = Async.withAsync . wrapThreadBody | ||
|
||
wrapThreadBody :: HasCallStack => IO a -> IO a | ||
wrapThreadBody = id | ||
--wrapThreadBody body = do | ||
-- tid <- myThreadId | ||
-- writeFile ("tmp/" ++ show tid) $ prettyCallStack callStack | ||
-- body | ||
|
||
{------------------------------------------------------------------------------- | ||
Wrap exceptions with a callstack | ||
-------------------------------------------------------------------------------} | ||
|
||
data STMException = STMException CallStack SomeException | ||
deriving stock (Show) | ||
deriving anyclass (Exception) | ||
|
||
-- | Rethrow STM exceptions with a callstakc | ||
-- | ||
-- This is especially helpful to track down "blocked indefinitely" exceptions. | ||
-- | ||
-- Implementation note: To catch such exceptions, we /must/ have the exception | ||
-- handler /outside/ of the STM transaction. | ||
atomically :: HasCallStack => STM a -> IO a | ||
atomically action = | ||
STM.atomically action `catch` (throwIO . STMException callStack ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.