effect icon indicating copy to clipboard operation
effect copied to clipboard

Preserve Span on Interruption

Open mikearnaldi opened this issue 1 year ago • 8 comments

The following code:

import { Effect, Fiber } from "effect"

const program = Effect.gen(function*() {
  const fiber = yield* Effect.fork(
    Effect.uninterruptibleMask((restore) =>
      restore(
        Effect.sleep("1 second").pipe(
          Effect.withSpan("sleep")
        )
      ).pipe(
        Effect.tapErrorCause((cause) => Effect.logError("Got cause:", cause))
      )
    )
  )

  yield* Effect.sleep("250 millis")
  yield* Fiber.interrupt(fiber)
  yield* Fiber.await(fiber)
  yield* Effect.logInfo("Done")
})

Effect.runFork(program)

now prints:

michaelarnaldi@Michaels-MacBook-Pro effect % pnpm tsx scratchpad/interrupt-span.ts 
timestamp=2024-09-09T15:43:01.173Z level=ERROR fiber=#1 message="Got cause:" cause="InterruptedException: Fiber Interrupted by: #0
    at sleep (/Users/michaelarnaldi/repositories/effect/scratchpad/interrupt-span.ts:8:18)"
timestamp=2024-09-09T15:43:01.175Z level=INFO fiber=#0 message=Done
michaelarnaldi@Michaels-MacBook-Pro effect % 

I am not too sure this is a wanted & helpful feature, up for discussion

mikearnaldi avatar Sep 09 '24 15:09 mikearnaldi

🦋 Changeset detected

Latest commit: f400eaa38eda67f5720410e8661b247566afc061

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 31 packages
Name Type
effect Minor
@effect/cli Major
@effect/cluster-browser Major
@effect/cluster-node Major
@effect/cluster-workflow Major
@effect/cluster Major
@effect/experimental Major
@effect/opentelemetry Major
@effect/platform-browser Major
@effect/platform-bun Major
@effect/platform-node-shared Major
@effect/platform-node Major
@effect/platform Major
@effect/printer-ansi Major
@effect/printer Major
@effect/rpc-http Major
@effect/rpc Major
@effect/schema Major
@effect/sql-d1 Major
@effect/sql-drizzle Major
@effect/sql-kysely Major
@effect/sql-mssql Major
@effect/sql-mysql2 Major
@effect/sql-pg Major
@effect/sql-sqlite-bun Major
@effect/sql-sqlite-node Major
@effect/sql-sqlite-react-native Major
@effect/sql-sqlite-wasm Major
@effect/sql Major
@effect/typeclass Major
@effect/vitest Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Sep 09 '24 15:09 changeset-bot[bot]

I think it is worthwhile, debugging interrupts is painful at the moment.

tim-smart avatar Sep 10 '24 00:09 tim-smart

I think it is worthwhile, debugging interrupts is painful at the moment.

it is but not sure how this helps debugging interrupts, it tells you where the program stopped and not who stopped it

mikearnaldi avatar Sep 10 '24 07:09 mikearnaldi

/rebase

mikearnaldi avatar Sep 10 '24 09:09 mikearnaldi

/rebase

tim-smart avatar Sep 10 '24 23:09 tim-smart

it is but not sure how this helps debugging interrupts, it tells you where the program stopped and not who stopped it

I feel like we could capture a span where .interrupt is called.

tim-smart avatar Sep 10 '24 23:09 tim-smart

It seems that is what you did in the latest commit? We could have the origin span and the receiver span, and then maybe set the error cause to the origin if present.

tim-smart avatar Sep 10 '24 23:09 tim-smart

It seems that is what you did in the latest commit? We could have the origin span and the receiver span, and then maybe set the error cause to the origin if present.

No what I did is capture where Effect.interruptible is called not where Fiber.interrupt is

mikearnaldi avatar Sep 10 '24 23:09 mikearnaldi