uv__read should stop reading when alloc_cb can't allocate #752

sck opened this Issue Mar 24, 2013 · 4 comments


None yet
4 participants

sck commented Mar 24, 2013

In my project I am using a static buffer that has a reasonable size but if it's full I just like to close the connection and reconnect. This is, however, not possible with uv__read right now because alloc_cb failure will just raise an assert, and the calls to uv_read_stop() and uv_close() that were initiated by my alloc_cb are never executed.


bnoordhuis commented Mar 25, 2013

I propose a change where alloc_cb calls uv_read_stop() and returns a zero-length buffer. It's a little more work for the user but it lets us catch bugs where the user inadvertently returns a zero-length buffer. In pseudo-code, it would look like this:

uv_buf_t buf = stream->alloc_cb(stream, size);
if (buf.len == 0) {
  assert((stream->flags & UV_READING) == 0 && "buf.len=0 but stream is still active");
  return;  /* User can't or won't handle read. */

@piscisaureus Does that work for you?


saghul commented Mar 25, 2013

@bnoordhuis what about calling the read_cb with UV_ENOBUFS as the error?


bnoordhuis commented Mar 25, 2013

That's fine too.


piscisaureus commented Mar 25, 2013

@saghul, @bnoordhuis I like both your suggestions equally well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment