workers-sdk
workers-sdk copied to clipboard
vite-plugin: `vite dev` does not throw an error when async i/o runs outside a request context
What versions & operating system are you using?
[email protected], @cloudflare/vite-plugin:1.5.0
Please provide a link to a minimal reproduction
https://github.com/threepointone/test-vite-wrangler-async-io
Describe the Bug
workerd should throw an error when async i/o is run outside of a request context. for example, this script should throw:
setTimeout(() => {
console.log("timer fired");
}, 1000);
export default {
async fetch(request, env, ctx) {
return new Response("Hello World");
},
};
when run with wrangler dev, this throws as expected. but it does NOT throw when run with vite dev.
Please provide any relevant error logs
No response
We'll have a look at trying to solve this, but it's probably going to be quite tricky. The issue is that in Vite everything is in a request context (because it's all dynamically loaded code orchestrated by a durable object), and so we can't rely on workerd blocking this. We could maybe do some funky things with ALS to mimic workerd's blocking?
That all said, is this causing any major issues? That code should fail at deploy time because of the validator, AFAIK
That's kinda the problem, folks work on their project, it works ok, then it fails to deploy (and it's hard to debug what happened). This happened with openai agents sdk, and I had to step in and spend a bunch of time figuring out where it was happening.