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

ReadableStreamDefaultController prototype methods/getters all fail in with "this" is not a ReadableStreamDefaultController #17837

Open
colelawrence opened this issue Mar 1, 2025 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@colelawrence
Copy link

What version of Bun is running?

1.2.1+ce532901c

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

I'm not sure exactly how to reproduce this bug, because it occurs when a certain number of conditions are met within the Effect fiber runtime & scheduler.

It occurs in code that looks like this, but I suspect that the reproduction requires certain conditions to come together for the event loop/runtime to cause this.

export const toReadableStreamRuntime = /*#__PURE__*/dual(args => isStream(args[0]), (self, runtime, options) => {
  let i = (++j * 1e6);
  const runFork = Runtime.runFork(runtime);
  let currentResolve = undefined;
  let fiber = undefined;
  const latch = Effect.unsafeMakeLatch(false);
  return new ReadableStream({
    start(controller) {
      const id = `READABLE-${++i}`;
      fiber = runFork(runForEachChunk(self, chunk => latch.whenOpen(Effect.sync(() => {
        try {
          console.log(id, "unsafe close");
          latch.unsafeClose();
          for (const item of chunk) {
            console.log(id, "enqueue", item);
            controller.enqueue(item);
          }
          console.log(id, "enqueue done");
          currentResolve();
          console.log(id, "resolve done");
          currentResolve = undefined;
        } catch (error) {
          console.log(id, "error", error);
          throw error;
        }
      }))));
      fiber.addObserver(exit => {
        if (exit._tag === "Failure") {
          try {
            controller.error(Cause.squash(exit.cause));
          } catch (error) {
            debugger
            throw error;
          }
        } else {
          controller.close();
        }
      });
    },
    pull() {
      return new Promise(resolve => {
        currentResolve = resolve;
        Effect.runSync(latch.open);
      });
    },
    cancel() {
      if (!fiber) return;
      return Effect.runPromise(Effect.asVoid(Fiber.interrupt(fiber)));
    }
  }, options?.strategy);
});

What is the expected behavior?

Should be able to access all the getters/functions on ReadableStreamDefaultController

What do you see instead?

Image

Additional information

Related to Effect-TS/effect#4538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant