Does libuv guarantee the order in which callbacks associated with an `uv_process_t` will be invoked?

67 views
Skip to first unread message

Thiago Arruda

unread,
Jul 7, 2014, 3:38:27 PM7/7/14
to li...@googlegroups.com
When a process is spawned with stdout/stderr connected to pipes, there are three associated callbacks:

- One for stdout data
- One for stderr data
- One for when the process exits.

When a stream reaches EOF, it's read callback will be invoked with an error set. That means when a process exits, all three callbacks will be invoked.

Is it guaranteed that the last callback of a process will be the `uv_process_t.exit_cb`? I need to know this to determine when the process handles can be safely closed.

Thanks in advance

Thiago.

Saúl Ibarra Corretgé

unread,
Jul 7, 2014, 6:22:51 PM7/7/14
to li...@googlegroups.com, indut >> Fedor Indutny
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I don't think we guarantee such a thing, and it's actually not that
obvious from the code :-S Fedor, any idea?


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

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

iQIcBAEBAgAGBQJTux17AAoJEEEOVVOum8BZzNoQAL7iRJCiZWdHCC7hYQQaNBMw
CEAtvlcNL8RiPuZZND2EPfwpvPTx9zTRGQP+9G6HPrTIkZoYM5nHH1gAx08yNMIL
G5OATMkNrw9/rXgGpSqJW4qA4bPP6h2vcQzKy5bqv/rZ1zVMvkLpdrpgJdTIb+oM
a/7Dk5KQiWBhcqO/EqTy+10vnjrUPIXScfwjV6hNZT+R0oUzXIaILYk6fXZbEamq
DOA0rmtYXbl6zxqFl+FMEc4Ab5yemAPq0Ecu/moy3gm5z4PSxysgEkUhvG1vAlW2
ciUak2cFA5f3J8Alj3hO//R1nCvNH+XKq+slncOuzgD88OR/rWZy3wQ53JCqlX62
V0ALiQ9hG65+C3P8cqVLxIxbai4vL7M4H1dNiCJ1jPyOGDL3uj173PdHjTvMbDQt
C6ubfTOlXEsQ3124mEdj1DvIxv3XN1wfQrV63Wr8G3CpwYoNIfZoJGcg6l8Knb1e
Xn06/LKcDeT8bazbcQ22ToMcvfa00vHGyn46JzHVyNTWknvZYKJleH1mPaNk0pkL
DgtRQpElVQ3M6wm5vaQPbVfGkW5zb1vXdUSd85NVihDHiO/WOY15XlzG+HJjUOXq
nnuIaWS3dr+WZuU39zs2nCkcwZhn67XtGWpe50cABEVL7+TCP1dYDu6qabOW9jN9
C/GI638jbJCPtbK8tF8r
=SJoG
-----END PGP SIGNATURE-----

Fedor Indutny

unread,
Jul 8, 2014, 1:45:38 AM7/8/14
to li...@googlegroups.com
We do not provide any guarantees, and it'd be hard for us to do so.

Thanks for raising up the question!



--
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.

Thiago Padilha

unread,
Jul 11, 2014, 7:51:47 AM7/11/14
to li...@googlegroups.com

I was already handling this by counting callbacks and wondered if it was really necessary. Thanks for the answer anyway

Bert Belder

unread,
Oct 22, 2014, 10:10:39 PM10/22/14
to li...@googlegroups.com
> Is it guaranteed that the last callback of a process will be the `uv_process_t.exit_cb`? I need to know this to determine when the process handles can be safely closed.

You should explicitly close the stdio pipes.

Read callbacks can indeed come in after the exit_cb is fired. Sometimes data may still be lingering in the stdout/stderr pipes which will be flushed after the exit callback.

You have to realize that there are scenarios in which the pipes stay open long after the process exits. This may for example happen when the child process creates another process that inherits the child's stdio pipes. The grand-child may outlive it's parent.

- Bert

Thiago Padilha

unread,
Oct 23, 2014, 9:04:28 AM10/23/14
to li...@googlegroups.com
Bert, thanks for the info.

After adding calls to uv_close on the close_cb of my uv_process_t, all
my problems were fixed!
Reply all
Reply to author
Forward
0 new messages