Skip to content

withAsync can leak threads in MaybeT/ExceptT monads #34

@Shimuuar

Description

@Shimuuar

Reproducer:

module Q where

import Control.Concurrent
import Control.Monad
import Control.Monad.Trans.Maybe
import Control.Monad.IO.Class
import Control.Concurrent.Async.Lifted

dumb :: IO ()
dumb = forever $ do threadDelay 100000
                    putStrLn "still alive"
  
go :: MaybeT IO ()
go = withAsync (liftIO dumb) $ \_ ->
  liftIO (threadDelay 10000) >> mzero

instead of killing async after go is finished thread is left running. Reason for that is simple: withAsyncUsing uses monadic bind from m which could abort early without ever reaching stop

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions