Execution Context Canceled When Returning Response Object with Stubs from Service Worker
When calling a method on a Service Worker that returns a Response object containing stubs (remote objects), and then returning that Response object from the caller Worker, the execution context of the called Service Worker is canceled prematurely, even after attempting to dispose the Response object using the using declaration or explicit disposal.
ServiceA Worker (wrangler.toml)
ServiceA Worker (src/index.ts)
ServiceB Worker (wrangler.toml)
ServiceB Worker (src/index.ts)
Expected Behavior:
The Response object returned from fetchData in ServiceB should be properly disposed, and the execution context of ServiceB should remain active until all stubs have been disposed.
Actual Behavior:
The execution context of ServiceB is being canceled prematurely, even after attempting to dispose the Response object using the using declaration or explicit disposal in ServiceA. But in my case, the fetch call that happened in serviceB works fine, but in the logs of ServiceA and ServiceB it's showing as the event is being canceled, might be an issue with logpush, not sure.
1 Reply
we should fully consume the Response before logging or utilizing it further.
so by awaiting the text() method, we ensure that the entire Response stream is consumed before attempting to log it. This prevents the stream from being closed prematurely due to the async nature of the queue processing.