[WIN32,TTY] 'uv_alloc_cb' is called before 'uv_read_start' returns.

18 views
Skip to first unread message

Renato Maia

unread,
Jun 25, 2021, 8:09:41 PMJun 25
to li...@googlegroups.com
In libuv v1.x (963ecc82) in Windows 10, I noticed that 'uv_read_start'
over a 'uv_tty_t' calls the 'uv_alloc_cb' before it returns. The same
does not seem to happen in Linux, nor even in Windows if we use other
'uv_tcp_t' ir 'uv_pipe_t'. Is this expected?

It was a problem for me because my code only sets up the environment
for the callback if 'uv_read_start' returns successfully (err >= 0).
Also, from the way the general design of the event loop of libuv is
described (http://docs.libuv.org/en/v1.x/design.html), I was surprised
that callbacks can be invoked inside an API call.

I attached a small example to reproduce this scenario. On Linux, it
works as expected:

```
libuv_ttyinlineread.c:38:main(server started!)
I type this line
libuv_ttyinlineread.c:14:on_alloc(size=65536)
libuv_ttyinlineread.c:9:on_read(nread=17)
```

But on Windows 10, I get this:

```
libuv_ttyinlineread.c:14:on_alloc(size=8192)
Assertion failed: handle->data, file libuv_ttyinlineread.c, line 15
```

Thanks in advance.

--
Renato Maia
libuv_ttyinlineread_c.txt

Ben Noordhuis

unread,
Jun 26, 2021, 4:07:56 AMJun 26
to li...@googlegroups.com
Yes, that's expected. Libuv sometimes has to commit memory upfront.

maia....@gmail.com

unread,
Jun 29, 2021, 6:57:30 PMJun 29
to libuv
On Saturday, June 26, 2021 at 5:07:56 AM UTC-3 Ben Noordhuis wrote:
Yes, that's expected. Libuv sometimes has to commit memory upfront.

Is this something particular to the 'uv_alloc_cb' ? Or any callback can potentially be invoked before its setup function to return successfully?

Ben Noordhuis

unread,
Jun 30, 2021, 7:30:17 PMJun 30
to li...@googlegroups.com
It's specific to uv_alloc_cb and the callbacks you set with
uv_replace_allocator().
Reply all
Reply to author
Forward
0 new messages