Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using timeout in runFork causes warning about unhandled error #2721

Open
maxgr0 opened this issue May 9, 2024 · 0 comments
Open

Using timeout in runFork causes warning about unhandled error #2721

maxgr0 opened this issue May 9, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@maxgr0
Copy link

maxgr0 commented May 9, 2024

What version of Effect is running?

3.1.3

What steps can reproduce the bug?

const task = () => Effect.fail(new Error('test')) as Effect.Effect<string, Error>;

const makeTaskHandler = (testEventEmitter: EventEmitter) =>
  Effect.gen(function* () {
    const runHandler = Runtime.runFork(yield* Effect.runtime<never>());

    const processor = () =>
      new Promise((resolve, reject) =>
        runHandler(
          pipe(
            task().pipe(Effect.timeout(Duration.millis(200))),
            Effect.tapBoth({
              onSuccess: () => Effect.logInfo('success'),
              onFailure: () => Effect.logError('failure'),
            }),
            Effect.matchEffect({
              onSuccess: (result) => Effect.sync(() => resolve(result)),
              onFailure: (exception) =>
                Effect.sync(() =>
                  reject(
                    exception instanceof Error ? exception : new Error('Handler failed'),
                  ),
                ),
            }),
          ),
        ),
      );

    testEventEmitter.on('test-event', processor);
  });

const program = Effect.gen(function* () {
  const eventEmitter = new EventEmitter();

  yield* makeTaskHandler(eventEmitter);

  yield* Effect.sleep('1 second');

  eventEmitter.emit('test-event');
});

Effect.runPromise(program.pipe(Logger.withMinimumLogLevel(LogLevel.Debug)));

What is the expected behavior?

When an effect is wrapped within an Effect.timeout and fails because of any other reason (before the timeout kicks in), it should not lead to a warning about an unhandled error within a Fiber.

When trying to debug this behavior, I removed the .pipe(Effect.timeout(Duration.millis(200))) and got the normal message which was expected:

timestamp=2024-05-09T21:07:53.136Z level=ERROR fiber=#1 message=failure

What do you see instead?

Effect logs a message about a Fiber terminating with an unhandled error.

timestamp=2024-05-09T21:07:53.132Z level=DEBUG fiber=#2 message="Fiber terminated with an unhandled error"
timestamp=2024-05-09T21:07:53.136Z level=ERROR fiber=#1 message=failure

Additional information

In case the timeout itself kicks in, the message about an unhandled error is also not coming up. Only if the wrapped effect fails before the timeout kicks in.

@maxgr0 maxgr0 added the bug Something isn't working label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant