-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Futures are skipped When Using JsFuture with Web Worker in Chrome #3609
Comments
more info about my setup: cargo 1.73.0-nightly (45782b6b8 2023-07-05) how i build:
my config.toml: [unstable]
build-std = ["std", "panic_abort"]
[target.wasm32-unknown-unknown]
rustflags = ["-Ctarget-feature=+atomics,+bulk-memory,+mutable-globals", "--cfg=web_sys_unstable_apis"] how i call the module: <script type="module">
import init from './client.js';
document.addEventListener("play", async function(){
await init();
}, false);
</script> worker code: import init, {wasm_thread_entry_point} from "WASM_BINDGEN_SHIM_URL";
self.onmessage = event => {
let [ module, memory, context ] = event.data;
init(module, memory).catch(err => {
console.log(err);
// Propagate to main `onerror`:
setTimeout(() => { throw err; });
throw err;
}).then(() => {
wasm_thread_entry_point(context);
});
}; note: |
A minimal reproducible example would go a long way helping you debug this. |
I was able to test JsFuture in a non-worker environment, and the issue happens as well! I kept doing A/B testing about 30 times on my codebase, until added and removed the following: WIth atomics flag, JsFutures has the "skipping behaviour" that i observed in chrome (but not firefox) hopefully we can figure out how atomics is affecting it. |
i digged a bit into the codes, and i saw the specific atomic flag and branch note: i use a singlethreaded async runtime inside webworker, and the multithreading branch was not working for me due to the bug |
Be careful about that, I'm not exactly aware of all the details, but: #1379. |
uhm actually after further testing, the single threaded branch didn't await inside the worker properly: i will just use the closure solution for now then |
We are experiencing an issue where JsFuture::from(reader.read()).await in a Web Worker drops over 80% of packets in Chrome. This issue does not occur in Firefox or when using native JavaScript in Chrome.
Code Snippet:
The following Rust code runs in a Web Worker and awaits the web-transport datagrams reader, and experiences packet loss in Chrome:
For comparison, the JavaScript version that works correctly:
i called the javacript code above using wasm-bindgen, with the reader as argument. The js function is located in the worker. So this is the best isolation i could do for JsFuture::from(reader.read()).await.
The observed behaviour is that awaiting when there is a group of them ready to be received, the in-between as skipped.
The text was updated successfully, but these errors were encountered: