Skip to content

Timeout on a canceled IO #3396

@Jasper-M

Description

@Jasper-M

If you set a timeout on a task that somehow cancels itself, the end of the timeout will be awaited instead of handing back control immediately. Even more surprising (to me) is that timeoutAndForget never hands back control in that case.

scala> IO.canceled.unsafeRunTimed(4.seconds) // errors immediately
java.util.concurrent.CancellationException: The fiber was canceled

scala> IO.canceled.timeout(3.seconds).unsafeRunTimed(4.seconds) // errors after 3 seconds
java.util.concurrent.TimeoutException: 3 seconds

scala> IO.canceled.timeoutAndForget(3.seconds).unsafeRunTimed(4.seconds) // returns after 4 seconds
val res63: Option[Unit] = None

In order to avoid this I guess you would have to surface the cancellation as an Exception.

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