Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Some functionality can only be performed while handling a request" whenever running in a debugger #292

Closed
JosXa opened this issue Jun 20, 2022 · 6 comments
Labels
dependency Issue in dependency

Comments

@JosXa
Copy link

JosXa commented Jun 20, 2022

My project runs fine using a regular start/dev command. However, whenever a debugger from VSCode or WebStorm attaches itself to the process, all requests subequently fail with

GET /myurl 500 Internal Server Error (22891.94ms)
[mf:err] GET /myurl: Error: Some functionality, such as asynchronous I/O (fetch, Cache API, KV), timeouts (setTimeout, 
setInterval), and generating random values (crypto.getRandomValues, crypto.subtle.generateKey), can only be performed wh
ile handling a request.

I am 100% certain that my code is not doing any i/o outside of its main request handler. How can we help to reproduce this, as in #207 the same issue occurs?

@dan-lee
Copy link
Contributor

dan-lee commented Jun 24, 2022

From the v2.0 changelog

To match the behaviour of the Workers runtime, some functionality, such as
asynchronous I/O (fetch, Cache API, KV), timeouts (setTimeout,
setInterval), and generating cryptographically-secure random values
(crypto.getRandomValues, crypto.subtle.generateKey), can now only be
performed while handling a request.

This behaviour can be disabled by setting the
--global-async-io/globalAsyncIO, --global-timers/globalTimers and
--global-random/globalRandom options respectively, which may be useful for
tests or libraries that need async I/O for setup during local development.
Note the Miniflare Jest environment automatically enables these options.

Maybe the debugger mode does something magic that requires you to disable this feature.

@JosXa
Copy link
Author

JosXa commented Jun 26, 2022

That's also my suspicion. Disabling the warning does the trick as a workaround.

@mrbbot
Copy link
Contributor

mrbbot commented Jul 2, 2022

Hey! 👋 Thanks for reporting this. I'm able to reproduce it and will investigate further. Will aim to fix in the next release.

@mrbbot mrbbot added the bug Something isn't working label Jul 2, 2022
@mrbbot mrbbot added this to the 2.6.0 milestone Jul 2, 2022
@mrbbot mrbbot modified the milestones: 2.6.0, 2.7.0 Jul 9, 2022
@mrbbot mrbbot modified the milestones: 2.7.0, 2.8.0 Aug 19, 2022
@huw
Copy link
Contributor

huw commented Sep 3, 2022

I’ve suddenly started running into this a lot and not sure what the cause is. Occasionally restarting the debugger in VS Code works fine, but usually it breaks it.

For anyone else running into it, remember to enable global_async_io, global_timers and global_random in all of your mounted workers.

@mrbbot
Copy link
Contributor

mrbbot commented Sep 3, 2022

Hey everyone! 👋 Looks like this is because of an issue in Node: nodejs/node#43148. A fix has been merged (nodejs/node#44423) which should be released soon. 👍 It seems this issue only affects Node 18 though, so in the meantime, you may want to downgrade to Node 16.

@mrbbot mrbbot added dependency Issue in dependency and removed bug Something isn't working labels Sep 3, 2022
@mrbbot mrbbot removed this from the 2.8.0 milestone Sep 3, 2022
@mrbbot
Copy link
Contributor

mrbbot commented Sep 13, 2022

Hey again! Looks like this fix was released as part of Node 18.9.0. Upgrading should resolve this issue! 🎉

@mrbbot mrbbot closed this as completed Sep 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency Issue in dependency
Projects
None yet
Development

No branches or pull requests

4 participants