BrowserWorkerRunner: port finalizer throws when the worker global has no close() (Bun)
BrowserWorkerRunner.make registers a finalizer for each port that calls port.close() unconditionally:
Effect.sync(() => {
port.removeEventListener("message", onMsg)
port.removeEventListener("messageerror", onMessageError)
port.close()
})In a dedicated worker, layer passes the worker global as the port. Bun's worker global implements postMessage and addEventListener/removeEventListener, but has no close() (Bun 1.4.2):
// worker.ts, run with `new Worker(new URL("./worker.ts", import.meta.url))` under Bun
postMessage({ hasClose: "close" in self, type: typeof (self as any).close })
// => { hasClose: false, type: "undefined" }So when the runner shuts down in a Bun worker (for example in a bun test suite that exercises browser worker code), the finalizer throws TypeError: port.close is not a function.
The owning parent terminates the worker anyway, so skipping close() when it is missing is safe. #6680 already fixed the messageerror listener removal in the same finalizer; this is the remaining part.
Environment: @effect/[email protected], Bun 1.4.2, Windows x64. Still present on main.
Source: Effect-TS/effect