Binary plugin using libevent stalls node event loop #43882
Replies: 5 comments 5 replies
-
I thought about it again, the enqueue is called from a c++ worker, so under the hood uv_async is scheduling the callback to the enqueue. Is it possible that it ( async callback) is executed in the event loop at a point, where the newly created callbacks inside enqueue do not cause poll to return immediately? |
Beta Was this translation helpful? Give feedback.
-
Ok, adding inside all callbacks, which are called from the c++ worker (so the libuv async callback effectively) around the function body, a |
Beta Was this translation helpful? Give feedback.
-
I can't answer your question without looking at your code in detail (which I'm not going to do because time) but the behavior you describe sounds like a classic case of assuming 1 uv_async_send() call == 1 uv_async_cb call. There's no such relation, libuv can and will coalesce uv_async_send() calls into a single callback call. I'll convert this to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Another pointer, all io is coming from the binary plugin. So there is no socket on the libuv loop that will fire, except for the timers, etc. |
Beta Was this translation helpful? Give feedback.
-
Ok, I have now, converted the whole addon from nan to napi. |
Beta Was this translation helpful? Give feedback.
-
Version
v16.16.0
Platform
Microsoft Windows NT 10.0.19044.0 x64
Subsystem
Main event loop? webstreams?
What steps will reproduce the bug?
Ok, I am not completely sure, if it is really a bug, probably it is related to the event loop. (So may be it should belong to the support category).
I am currently writing a plugin, which uses the quiche library to provide http/3 webtransport support for node., I am currently working to get it to work on windows (https://github.com/fails-components/webtransport/tree/windows).
It runs fine on Linux.
But on windows, after data packets are enqueued to the readable stream (see
npm test
on the windows branch), they take sometimes seconds (!) to be passed to the await from the reader.Steps to reproduce, install the windows branch, let the library compile (MSVc build tools including clang-cl required) and run
npm test
.For example:
incom ud <Buffer 4d 4e 4f> 1657995037760
incom ud <Buffer 50 51 52> 1657995042771
two datagrams received enqueue almost at the same time (I inspected the time), but emitted after 10 s delay (last number is Date.now())
However, if I include a setInterval( ) function with a short interval I do not see these stalls.
So it seems, that the result from
enqueue
or maybe the promise is not handled in the event loop cycle and the setInterval just triggers the event loop to break and do the remaining tasks.How often does it reproduce? Is there a required condition?
Every run with different stalls length, at least one-third of output is stalled.
What is the expected behavior?
No stalls of the event loop, time should only differ by some ms.
What do you see instead?
Delays in of multiples of seconds.
Additional information
The library uses libevent for the http/3 event loop. So I fear, that it interferes with the libuv event loop is this possible? Or what else could cause the behavior?
Beta Was this translation helpful? Give feedback.
All reactions