Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 3cce8ab

Browse files
orangemochatrevnorris
authored andcommitted
uv: float win pipe patch
Float patch to fix pipe on Windows. Original commit message: win: fix pipe blocking writes In the code path for pipe blocking writes, WriteFile is already posting a completion packet to the I/O completion port. POST_COMPLETION_FOR_REQ was causing the same request to get returned twice by GetCompletionStatusEx. Also on the same code path, we were waiting on the wrong event. We need to update queued_bytes and write_queue_size when a blocking write request completes asynchronously. Ref: libuv/libuv#238 Reviewed-By: Julien Gilli <[email protected]> PR-URL: #9179
1 parent 2411bea commit 3cce8ab

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

deps/uv/src/win/pipe.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,7 +1347,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
13471347
}
13481348

13491349
/* Request queued by the kernel. */
1350-
req->queued_bytes = uv__count_bufs(bufs, nbufs);
1350+
req->queued_bytes = bufs[0].len;
13511351
handle->write_queue_size += req->queued_bytes;
13521352
} else if (handle->flags & UV_HANDLE_BLOCKING_WRITES) {
13531353
/* Using overlapped IO, but wait for completion before returning */
@@ -1372,12 +1372,13 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
13721372
/* Request completed immediately. */
13731373
req->queued_bytes = 0;
13741374
} else {
1375-
assert(ipc_header_req != NULL);
13761375
/* Request queued by the kernel. */
1377-
if (WaitForSingleObject(ipc_header_req->overlapped.hEvent, INFINITE) !=
1376+
req->queued_bytes = bufs[0].len;
1377+
handle->write_queue_size += req->queued_bytes;
1378+
if (WaitForSingleObject(req->overlapped.hEvent, INFINITE) !=
13781379
WAIT_OBJECT_0) {
13791380
err = GetLastError();
1380-
CloseHandle(ipc_header_req->overlapped.hEvent);
1381+
CloseHandle(req->overlapped.hEvent);
13811382
return uv_translate_sys_error(err);
13821383
}
13831384
}
@@ -1386,7 +1387,6 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
13861387
REGISTER_HANDLE_REQ(loop, handle, req);
13871388
handle->reqs_pending++;
13881389
handle->write_reqs_pending++;
1389-
POST_COMPLETION_FOR_REQ(loop, req);
13901390
return 0;
13911391
} else {
13921392
result = WriteFile(handle->handle,
@@ -1404,7 +1404,7 @@ static int uv_pipe_write_impl(uv_loop_t* loop,
14041404
req->queued_bytes = 0;
14051405
} else {
14061406
/* Request queued by the kernel. */
1407-
req->queued_bytes = uv__count_bufs(bufs, nbufs);
1407+
req->queued_bytes = bufs[0].len;
14081408
handle->write_queue_size += req->queued_bytes;
14091409
}
14101410

deps/uv/src/win/req-inl.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ INLINE static uv_req_t* uv_overlapped_to_req(OVERLAPPED* overlapped) {
9393
INLINE static void uv_insert_pending_req(uv_loop_t* loop, uv_req_t* req) {
9494
req->next_req = NULL;
9595
if (loop->pending_reqs_tail) {
96+
#ifdef _DEBUG
97+
/* Ensure the request is not already in the queue, or the queue
98+
* will get corrupted.
99+
*/
100+
uv_req_t* current = loop->pending_reqs_tail;
101+
do {
102+
assert(req != current);
103+
current = current->next_req;
104+
} while(current != loop->pending_reqs_tail);
105+
#endif
106+
96107
req->next_req = loop->pending_reqs_tail->next_req;
97108
loop->pending_reqs_tail->next_req = req;
98109
loop->pending_reqs_tail = req;

0 commit comments

Comments
 (0)