From be8b3513d3e696ba183cbfc7c4f4e1788afe867c Mon Sep 17 00:00:00 2001 From: zyxwvu Shi Date: Sun, 21 Jul 2019 11:55:23 +0800 Subject: [PATCH] unix: clear UV_HANDLE_READING flag before callback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The UV_HANDLE_READING stream flag should be removed before stopping the IO watcher and calling the callback. If the callback calls uv_read_start(), the IO watcher will be started then after the callback the UV_HANDLE_READING flag is removed. This will result in epoll constantly reporting POLLIN events while no one handles it, causing 100% CPU usage. PR-URL: https://github.com/libuv/libuv/pull/2382 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- src/unix/stream.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/stream.c b/src/unix/stream.c index 17b06a39..9de01e3c 100644 --- a/src/unix/stream.c +++ b/src/unix/stream.c @@ -1000,12 +1000,12 @@ uv_handle_type uv__handle_type(int fd) { static void uv__stream_eof(uv_stream_t* stream, const uv_buf_t* buf) { stream->flags |= UV_HANDLE_READ_EOF; + stream->flags &= ~UV_HANDLE_READING; uv__io_stop(stream->loop, &stream->io_watcher, POLLIN); if (!uv__io_active(&stream->io_watcher, POLLOUT)) uv__handle_stop(stream); uv__stream_osx_interrupt_select(stream); stream->read_cb(stream, UV_EOF, buf); - stream->flags &= ~UV_HANDLE_READING; }