DelSkayn / rquickjs

High level bindings to the quickjs javascript engine
MIT License
434 stars 59 forks source link

Spawned tasks are executed out of order #203

Closed richarddd closed 10 months ago

richarddd commented 10 months ago

Since futures are being removed using swap, it can mess up the order of how tasks are spawned: https://github.com/DelSkayn/rquickjs/blob/20d3008821c437b9cf94877a1f29e1b9e1c895d6/core/src/runtime/spawner.rs#L80 I also noticed that ordering can also be wrong if we don't sweep for all the completed futures in a poll and remove them.

This bug is a bit hard to reproduce in a simple use case since it depends on what the futures you are spawning are doing. Consider this simple example: The first task that completes will swap place with the last task, breaking the ordering of the next poll round.

This https://github.com/DelSkayn/rquickjs/pull/201 fixes the issue by looping over all tasks and then removing them from the list. List doesn't need to be atomic since we always push at the end.

DelSkayn commented 10 months ago

Should be fixed now that #201 is merged.