cloudflare / workers-rs

Write Cloudflare Workers in 100% Rust via WebAssembly
Apache License 2.0
2.55k stars 273 forks source link

The script will never generate a response: worker-build should emit all code inside a closure in a fetch function #255

Open samdenty opened 1 year ago

samdenty commented 1 year ago

Is there an existing issue for this?

What version of workers-rs are you using?

0.0.0

Describe the bug

Currently, the emitted code for worker-build has everything defined on the top-level.

I'm not sure why, but for some reason variables defined in the top level are re-used across requests.

I'm using the cached crate in my project, and because the wasm memory is re-used across requests - it stops working and hangs with The script will never generate a response.

I'm not sure if this is the intended behaviour, re-using the wasm memory across requests - maybe it was done for perf reasons?

But anyways I've ran into this issue of randomly hanging workers loads of times, and it's really annoying. I think the default should be not to re-use memory across requests

Steps To Reproduce

No response

zebp commented 1 year ago

I'm not sure if this is the intended behaviour, re-using the wasm memory across requests

This is intentional but I'm not too sure on why this would cause the cached to crash, can you make a small reproducible example?

samdenty commented 1 year ago

This only fixes the script will never generate response error for some cases, but I'm now running into https://github.com/cloudflare/rustwasm-worker-template/issues/22 which I think may? be the root cause