uv_loop_close() after uv_run() fails

766 views
Skip to first unread message

David Davidović

unread,
Mar 17, 2014, 10:05:58 PM3/17/14
to li...@googlegroups.com
Sorry if this a stupid question and shows my failure of grasping the basic concepts but I feel completely lost. So I have a watchdog timer whose job is to check every 30 seconds if there is a global kill switch flag set for the daemon, and if there is, it calls uv_stop() on the loop. (I understand I could just exit() from there but I like to keep valgrind happy at the end of program execution while debugging.) uv_run() returns after that, but when I try calling uv_loop_close() it returns UV_BUSY, and subsequent calls to uv_loop_delete() try the same and bomb with a SIGABRT because of an assertion failure. I'm not sure as to how this could happen, shouldn't uv_run() returning imply that the loop is done processing all of its data? Maybe if libuv runs its own threadpool somewhere, is there any way I can join on these threads as they could be the cause of the problem? How should I safely and successfully terminate the loop in such a condition?

TIA!

Fedor Indutny

unread,
Mar 18, 2014, 3:38:40 AM3/18/14
to li...@googlegroups.com
Heya!

Excerpt from a documentation about `uv_stop()`:

/*
* This function will stop the event loop by forcing uv_run to end
* as soon as possible, but not sooner than the next loop iteration.
* If this function was called before blocking for i/o, the loop won't
* block for i/o on this iteration.
*/

So the `uv_stop()` is forcing `uv_run()` to return, even if there are still
some active handles on the loop. You should close all of them before attempting
to call `uv_loop_close()`, and you could do while walking through all active
handles in loop:

/*
* Walk the list of open handles.
*/
UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);

Cheers,
Fedor.
> --
> You received this message because you are subscribed to the Google Groups
> "libuv" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to libuv+un...@googlegroups.com.
> To post to this group, send email to li...@googlegroups.com.
> Visit this group at http://groups.google.com/group/libuv.
> For more options, visit https://groups.google.com/d/optout.

Saúl Ibarra Corretgé

unread,
Mar 18, 2014, 4:17:17 AM3/18/14
to li...@googlegroups.com
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
See Fedor's response. Here is some code you could adapt to your needs:
https://github.com/joyent/libuv/blob/master/test/task.h#L221-L231


Cheers,

- --
Saúl Ibarra Corretgé
bettercallsaghul.com

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: Using GnuPG with Icedove - http://www.enigmail.net/

iQIcBAEBAgAGBQJTKAENAAoJEEEOVVOum8BZrF0P/2KbYYQ/P62HvyZY7Ymy7YuE
DB5va6ixBx0nlzNNk6INsrQf3i7dXNvsiBdMQYdde3f/cDpZxcB9rHGdsZhb89Vb
3HDcpXPEu9GvRU46MX4ntiBmS2eWQnA9QBV5pDGtNOj2gX9kjXavM9VHTXJk2HPq
2AHuItq9fBCBm5lPg1JOpf2toMjduS4EH2Lj8gObTMjamDQuTlYToCNTdRHZrgxL
K+XaI+uE0PwUylGqd1UHY08dyT7/jf/+2gEShkSnQgmSaSWbPHGw0qwsdEVHVoWT
Qwrwe9Hd6U2qjiEkBRcFuB83JkbMZ/160UxZT5/ByEiojaNayvdOIQhFPJi//NBO
Xek36r4nRnrkKPNz0idqN//uNr8JDGpJ5Lx1aELs3hew69ocOTvqZbpJs7r8e6mV
rH93OQU7I2CgsGVXFZ7zCV1StvsfWUt2laVyZ0IzQeIRDnjU1Vx8jpOBtMKeBhcE
VibWf8uB74mRNb7zTDSfVOA3ABQOHb9/XMCIu5+WVuMhdDiB1Cjl2aUmV23KtXOU
3MogROwuRLRyjAL+u9yEIaBgrjSOFEEJdK03g82fP50nF294eLOe/hgclq2QKJ6P
Z46QFZut2WxRvltU0jJDcfl0dugTx6j6g2yJJykj0LB+gojTAIWfLDsu9ckDAWSE
t/EPcMNK+Po6w7hnBs5U
=C1Fu
-----END PGP SIGNATURE-----

David Davidović

unread,
Mar 18, 2014, 5:54:33 AM3/18/14
to li...@googlegroups.com
Thanks for the speedy replies! I was under the impression that uv_run magically closes its handles when it returns. Didn't really think that one through :)

Cheers,
David

Reply all
Reply to author
Forward
0 new messages