-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
memory leak related to uv.send_async
#505
Comments
As far as I can tell, what's happening here is this, from the Libuv docs:
Luv currently expects a callback for every call of async_send to be able to free the memory for the data sent. Since not all sends are actually getting a callback called, though, that memory is never being freed. With your example code, a script that prints the numbers 1-100, and a couple prints added:
That's 2 async_cb's called for around 24 async_send calls. I'm not totally sure what the solution here would be, though. |
This is actually both a memory leak and a bug, as we are dropping data here that we shouldn't be. Minimal test case: test("multiple sends coalesce", function(print, p, expect, uv)
local async
async = uv.new_async(expect(function(data)
p(data)
uv.close(async)
end))
uv.async_send(async, 'this string will be lost')
uv.async_send(async, 'this string will be sent')
end) This will only print
meaning the I think we need to treat async data as a FIFO queue that we push onto in |
Seems like a good fix, but I wonder if any users are somehow relying on the libuv behavior. |
Libuv doesn't handle any passing of data, so the coalesced callbacks are reasonable there (the only intention of Libuv's async is just to wake up the loop from any thread). I guess it's possible that some Luv user is calling It's a little unfortunate that our binding does not match the Libuv code; it'd probably be better if we had split the actual data sending part into a |
Ah okay. A queue makes sense then. |
I don't mind changing my code at all, although I believe anyone using |
I made an ad-hoc by-line process output reader and it seems that I found a memory leak.
I wrapped into a min working example below. This is supposed to
uv.async_send
the lines of the output of a certain process. I setup a process that prints data endlessly. The output is stored incurrent_chunk
, but it's only temporary: each time data arrives, I look at the chunk and extract the lines, except for the last one (in case the last line did not arrive completely).If you keep the
uv.send_async
line below, memory consumption of thelua
process will grow endlessly. If you remove it, the memory consumption remains still. In both cases, each line is discarded.Happens with these lua versions:
The text was updated successfully, but these errors were encountered: