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

Unexpected NodeJS process hanging #2768

Open
dilame opened this issue May 17, 2024 · 2 comments
Open

Unexpected NodeJS process hanging #2768

dilame opened this issue May 17, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@dilame
Copy link
Contributor

dilame commented May 17, 2024

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.

@dilame dilame added the bug Something isn't working label May 17, 2024
@tim-smart
Copy link
Member

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

@mikearnaldi
Copy link
Member

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

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

3 participants