abbr / deasync

Turns async function into sync via JavaScript wrapper of Node event loop
MIT License
971 stars 73 forks source link

Nesting deasync cause endless loop, and maybe 100% CPU #158

Open loynoir opened 3 years ago

loynoir commented 3 years ago

What

  1. Nesting deasync.loopWhile cause endless loop + 100% CPU.
  2. Nesting deasync.sleep cause endless loop.

Reproduce

https://github.com/loynoir/reproduce-deasync-158.js

Reproduce

$ git clone https://github.com/loynoir/reproduce-deasync-158.js
$ npm install
$ npm test

Actual

$ reproduce_deasync_158_cpu=1 pnpm test
... // No output, 100% CPU.

$ unset reproduce_deasync_158_cpu
$ npm test
index.cjs waiting for ./index.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
plugin.cjs waiting for ./dependency.mjs
... // endless

Expected

No endlessloop. No 100% CPU.