From 80f2f826bf90b84e659321c0b7fd8af419acb85e Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Thu, 23 May 2013 07:16:00 +0200 Subject: [PATCH] unix: fix stream refcounting buglet Fix a buglet where uv_read_stop() would mark the handle as stopped even when there are in-progress write requests. This bug is unlikely to have affected anyone, the only case where it has a user-visible effect is when: a) the handle has been stopped for reading but not writing, and b) it's the last active handle in the event loop's pollset If both conditions are met, it's possible for the event loop to terminate prematurely. --- src/unix/stream.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 824de9f4..378f21c6 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -1307,9 +1307,10 @@ int uv_read2_start(uv_stream_t* stream, uv_alloc_cb alloc_cb, int uv_read_stop(uv_stream_t* stream) { - uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN); - uv__handle_stop(stream); stream->flags &= ~UV_STREAM_READING; + uv__io_stop(stream->loop, &stream->io_watcher, UV__POLLIN); + if (!uv__io_active(&stream->io_watcher, UV__POLLOUT)) + uv__handle_stop(stream); #if defined(__APPLE__) /* Notify select() thread about state change */