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)
name = "service-a"
main = "src/index.ts"
logpush = true

[env.dev]
workers_dev = true
services = [{ binding = "SERVICE_B", service = "service-b" }]


ServiceA Worker (src/index.ts)
export default {
async queue(batch, env) {

 // Approach 1: Using 'using' declaration
  using response = await env.SERVICE_B.fetchData();

  // Approach 2: Explicit disposal
  // response[Symbol.dispose]();
console.log('response', response)
}
}


ServiceB Worker (wrangler.toml)
name = "service-b"
main = "src/index.ts"
logpush = true


ServiceB Worker (src/index.ts)
export default class extends WorkerEntrypoint<Env> {
 async fetchData() {
  const response = new Response('Data from Service B');
  return response;
}
}

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.
image_10.png
Was this page helpful?