Effect-TS / effect

An ecosystem of tools to build robust applications in TypeScript

Home Page:https://effect.website

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected NodeJS process hanging

dilame opened this issue · comments

What version of Effect is running?

3.1.5

What steps can reproduce the bug?

const intervalStream = Stream.fromSchedule(Schedule.spaced('500 millis'))
  .pipe(Stream.tap(Console.log));

const program = Effect.gen(function* () {
    const pubsub = yield* PubSub.unbounded<Take.Take<number>>();
    yield* Effect.fork(Stream.runIntoPubSubScoped(intervalStream, pubsub));
})

NodeRuntime.runMain(Effect.awaitAllChildren(Effect.scoped(program)))

What is the expected behavior?

As far as i understand - runIntoPubSubScoped should be terminated once the Effect.scoped(program) has finished, then the forked effect will be completed with void result, then there will be no job in event loop, so NodeJS process will be terminated.`

What do you see instead?

NodeJS process hangs forever.

Additional information

I thought maybe it is because the stream is still running, so i added .pipe(Stream.tap(Console.log)), but there are no logs in console.

commented

It is because the fiber hasn't started when it hits Effect.awaitAllChildren, if we ensure the fiber has started first it will work: https://effect.website/play#83b4743a0952

Alternatively you can use .forkScoped to ensure it is properly shutdown: https://effect.website/play#328d73d41f10

It is because the fiber hasn't started when it hits Effect.awaitAllChildren, if we ensure the fiber has started first it will work: https://effect.website/play#83b4743a0952

Alternatively you can use .forkScoped to ensure it is properly shutdown: https://effect.website/play#328d73d41f10

still awaitAllChildren hanging is probably a bug