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

Commit dd0702a

Browse files
committed
win pipe: race condition on queueing uv_pipe_zero_readfile_thread_proc
fixes a race condition where if uv_close was called shortly after uv_read_start or a successful read and before the uv_pipe_zero_readfile_thread_proc thread started, that thread would try to read the mutex object after it had already been deleted
1 parent 6b74941 commit dd0702a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Diff for: src/win/pipe.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1114,7 +1114,6 @@ static DWORD WINAPI uv_pipe_zero_readfile_thread_proc(void* parameter) {
11141114
assert(handle->type == UV_NAMED_PIPE);
11151115

11161116
if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE) {
1117-
uv_mutex_lock(m); /* mutex controls *setting* of readfile_thread */
11181117
if (DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
11191118
GetCurrentProcess(), &hThread,
11201119
0, TRUE, DUPLICATE_SAME_ACCESS)) {
@@ -1248,9 +1247,13 @@ static void uv_pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) {
12481247
req = &handle->read_req;
12491248

12501249
if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
1250+
if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE)
1251+
uv_mutex_lock(&handle->pipe.conn.readfile_mutex); /* mutex controls *setting* of readfile_thread */
12511252
if (!QueueUserWorkItem(&uv_pipe_zero_readfile_thread_proc,
12521253
req,
12531254
WT_EXECUTELONGFUNCTION)) {
1255+
if (handle->flags & UV_HANDLE_PIPE_READ_CANCELABLE)
1256+
uv_mutex_unlock(&handle->pipe.conn.readfile_mutex);
12541257
/* Make this req pending reporting an error. */
12551258
SET_REQ_ERROR(req, GetLastError());
12561259
goto error;

0 commit comments

Comments
 (0)