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

platform-node: Worker shutsdown when client side interrupts a response stream #4576

Closed
schickling opened this issue Mar 10, 2025 · 2 comments · Fixed by #4580
Closed

platform-node: Worker shutsdown when client side interrupts a response stream #4576

schickling opened this issue Mar 10, 2025 · 2 comments · Fixed by #4580
Labels
bug Something isn't working platform

Comments

@schickling
Copy link
Contributor

schickling commented Mar 10, 2025

What version of Effect is running?

3.13.8

What steps can reproduce the bug?

Add serialized worker test case to:

  it('Serialized 2', () =>
    Effect.gen(function* (_) {
      const pool = yield* _(EffectWorker.makePoolSerialized({ size: 1 }))
      const people = yield* _(
        pool.execute(new GetPersonById({ id: 123 })),
        Stream.runCollect,
        Effect.timeout(2000),
        Effect.exit,
      )
      console.log(people)
      const people2 = yield* _(pool.execute(new GetPersonById({ id: 123 })), Stream.take(1), Stream.runCollect)
      console.log(people2)
      // assert.deepStrictEqual(Chunk.toReadonlyArray(people), [
      //   new Person({ id: 123, name: "test", data: new Uint8Array([1, 2, 3]) }),
      //   new Person({ id: 123, name: "ing", data: new Uint8Array([4, 5, 6]) })
      // ])
    }).pipe(Effect.scoped, Effect.provide(WorkerLive), Effect.runPromise))

And adjust serialized worker:

const WorkerLive = Runner.layerSerialized(WorkerMessage, {
  GetPersonById: (req) => {
    return Stream.make(
      new Person({ id: req.id, name: 'test', data: new Uint8Array([1, 2, 3]) }),
      new Person({ id: req.id, name: 'ing', data: new Uint8Array([4, 5, 6]) }),
    ).pipe(Stream.schedule(Schedule.fixed('1 second')))
  },

And run 'Serialized 2 test.

What is the expected behavior?

This work properly for platform-browser:

Image

What do you see instead?

But fails when running the same tests via the platform-node worker setup:

Image

My suspicion is that the worker runner doesn't just interrupt the handler but also shutsdown the worker itself.

Additional information

(Please ignore that the test output contains ChildProcessRunnerTest)

No response

@schickling schickling added bug Something isn't working platform labels Mar 10, 2025
@schickling
Copy link
Contributor Author

Update: Seems like the current platform-node worker behaviour is "flaky" as sometimes I seem to get the expected behaviour. e.g. in this run:

Image

But then it breaks again in the next run:

Image

@IMax153
Copy link
Member

IMax153 commented Mar 11, 2025

Closing this issue as a fix has been implemented 👍

Feel free to re-open or open a new issue if any additional problems persist.

@IMax153 IMax153 closed this as completed Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working platform
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants