Worker reload in `watch` mode doesn't close HTTP connections
(This is a reboot of https://github.com/cloudflare/miniflare/issues/173, with a working repro.)
As I understand it, when a Durable Object's code is updated on Cloudflare, all connected sockets are closed. This is a behavior mismatch with Miniflare, which does not disconnect upon code update in watch mode.
Steps to reproduce:
- Create a file called
worker.jswith the following:
export class DO {
fetch(request) {
let start = controller => {
setInterval(() => {
let now = new Date().toISOString()
let data = new TextEncoder().encode(now + '\n')
controller.enqueue(data)
}, 500)
}
let stream = new ReadableStream({start})
return new Response(stream)
}
}
export default {
fetch (request, env) {
return env.DO.get(env.DO.newUniqueId()).fetch(request)
}
}
- In a terminal window, run
miniflare worker.js -m -w -o DO=DOto run the worker inwatchmode. - In another terminal window, run
curl -N -v http://127.0.0.1:8787. - Observe that a timestamp is written every 500ms.
- Edit the
worker.jsfile, such as by adding a string tonow. - Note that
Worker reloaded!is logged to the terminal window from (1). - Note that the terminal window from (2) is unchanged; the string from (5) is not reflected, and the HTTP connection is not closed.
- Kill the miniflare process.
- Note that the HTTP connection has been closed in the terminal window from (2).
Hey! 👋 Thanks for raising this and apologies for the delayed response. We should be able to fix this with customsetInterval and setTimeout implementations that attached to the RequestContext of the Durable Object, which could contain a reference to the DurableObjectState. These could then be reset in the Durable Object plugin's beforeReload hook.
This issue should be fixed in Miniflare 3, which uses workerd. 👍