From 8a647d436fbbeaec3838781280e74ef531917f61 Mon Sep 17 00:00:00 2001 From: Bartosz Sosnowski Date: Thu, 1 Nov 2018 11:10:03 +0100 Subject: [PATCH] win, tcp: avoid starving the loop Limit the time a TCP read callback can be called on a single loop iteration to 32. Ref: https://github.com/libuv/libuv/commit/738b31eb3aff440ae75ff9f32ba61086a948c3f4 Fixes: https://github.com/libuv/libuv/issues/2027 PR-URL: https://github.com/libuv/libuv/pull/2049 Reviewed-By: Ben Noordhuis Reviewed-By: Santiago Gimeno Reviewed-By: Colin Ihrig --- src/win/tcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/win/tcp.c b/src/win/tcp.c index 8b6f0a5c99b..3ce5548c0a4 100644 --- a/src/win/tcp.c +++ b/src/win/tcp.c @@ -945,6 +945,7 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, uv_req_t* req) { DWORD bytes, flags, err; uv_buf_t buf; + int count; assert(handle->type == UV_TCP); @@ -999,7 +1000,8 @@ void uv_process_tcp_read_req(uv_loop_t* loop, uv_tcp_t* handle, } /* Do nonblocking reads until the buffer is empty */ - while (handle->flags & UV_HANDLE_READING) { + count = 32; + while ((handle->flags & UV_HANDLE_READING) && (count-- > 0)) { buf = uv_buf_init(NULL, 0); handle->alloc_cb((uv_handle_t*) handle, 65536, &buf); if (buf.base == NULL || buf.len == 0) {