Skip to content

Async.cancel does not work inside of withException #95

Open
@parsonsmatt

Description

@parsonsmatt

Related: #74

This is a minimal reproduction of the issue we're seeing.

  describe "withException" $ do
    it "should work when withAsync is in the handler" $ do
      let
        action =
          error "oops"
            `onException` do
              let
                timerAction n = do
                  threadDelay 1000000
                  when (n < 10) $ do
                    timerAction (n + 1)
              withAsync (timerAction 0) $ \a -> do
                cancel a
      action
        `shouldThrow`
          errorCall "oops"

This should finish instantaneously, but it actually waits for timerAction to complete - all 10 seconds of it. cancel is therefore broken inside of a withException or onException or even a bracket call.

What's very surprising about this behavior is that catch doesn't share it. catch works exactly like you'd expect, even though a very simple implementation of withException is withException action handler = catch action (\e -> handler e >> throwIO e).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions