Hey there!
Here is a "fun" problem I ran into when integrating lws into my small JS runtime (it's currently used for HTTP/WS clients and servers).
I'm using libuv as my platform layer, so there is already a loop going on, thus, I'm using lws with a foreign event loop: https://github.com/saghul/txiki.js/blob/b88afe7bbd0c2a5d695c217f114d06195a77c9c1/src/lws-utils.c#L202
I also enabled async DNS because I don't want DNS to block the JS event loop.
lws seems to create a number of internal uv handles (poll handles, the pipe for wakeup, etc).
The problem arises when some of those handles keep the libuv event loop alive, since that affects my runtime, as uv_run won't exit because of those handles.
In order to get going I'm currently patching lws to not ref any uv handles: https://github.com/saghul/txiki.js/blob/master/patches/lws.patch
This is not ideal, so my plan was to bring it up here once I had things working. That time is now! :-)
My thinking here is that when lws is used directly there is no change necessary. When used with a foreign event loop, consumers may want the handles to be unref'd in order to keep a tighter control over loop exit conditions. I wonder if some kind of flag during context creation would be acceptable?
There is an interesting situation, however: when async DNS is used, one would want DNS to take place, so I do want those handles to be ref'd. Since I couldn't tell the difference (I'm not very experienced with the internals) I went the easy route and unref'd everything, then relied on an async handle I created to decide when to keep the loop alive.
Is this something that has come up? I'm willing to provide a patch once we agree on the path forward :-)
Another option I thought of, but I'm not sure it's currently possible is to write my own event loop integration plugin. If it was possible to do that externally (ie, not require it be baked into lws) that would also work. Thoughts?
Thanks for lws! ❤️
Hey there!
Here is a "fun" problem I ran into when integrating lws into my small JS runtime (it's currently used for HTTP/WS clients and servers).
I'm using libuv as my platform layer, so there is already a loop going on, thus, I'm using lws with a foreign event loop: https://github.com/saghul/txiki.js/blob/b88afe7bbd0c2a5d695c217f114d06195a77c9c1/src/lws-utils.c#L202
I also enabled async DNS because I don't want DNS to block the JS event loop.
lws seems to create a number of internal uv handles (poll handles, the pipe for wakeup, etc).
The problem arises when some of those handles keep the libuv event loop alive, since that affects my runtime, as uv_run won't exit because of those handles.
In order to get going I'm currently patching lws to not ref any uv handles: https://github.com/saghul/txiki.js/blob/master/patches/lws.patch
This is not ideal, so my plan was to bring it up here once I had things working. That time is now! :-)
My thinking here is that when lws is used directly there is no change necessary. When used with a foreign event loop, consumers may want the handles to be unref'd in order to keep a tighter control over loop exit conditions. I wonder if some kind of flag during context creation would be acceptable?
There is an interesting situation, however: when async DNS is used, one would want DNS to take place, so I do want those handles to be ref'd. Since I couldn't tell the difference (I'm not very experienced with the internals) I went the easy route and unref'd everything, then relied on an async handle I created to decide when to keep the loop alive.
Is this something that has come up? I'm willing to provide a patch once we agree on the path forward :-)
Another option I thought of, but I'm not sure it's currently possible is to write my own event loop integration plugin. If it was possible to do that externally (ie, not require it be baked into lws) that would also work. Thoughts?
Thanks for lws! ❤️