Skip to content

Commit de067bc

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 28f5f06 commit de067bc

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
@@ -1078,7 +1078,6 @@ static DWORD WINAPI uv_pipe_zero_readfile_thread_proc(void* parameter) {
10781078
assert(handle->type == UV_NAMED_PIPE);
10791079

10801080
if (m) {
1081-
uv_mutex_lock(m); /* mutex controls *setting* of readfile_thread */
10821081
if (DuplicateHandle(GetCurrentProcess(), GetCurrentThread(),
10831082
GetCurrentProcess(), &hThread,
10841083
0, TRUE, DUPLICATE_SAME_ACCESS)) {
@@ -1211,9 +1210,13 @@ static void uv_pipe_queue_read(uv_loop_t* loop, uv_pipe_t* handle) {
12111210
req = &handle->read_req;
12121211

12131212
if (handle->flags & UV_HANDLE_NON_OVERLAPPED_PIPE) {
1213+
if (handle->readfile_mutex)
1214+
uv_mutex_lock(handle->readfile_mutex); /* mutex controls *setting* of readfile_thread */
12141215
if (!QueueUserWorkItem(&uv_pipe_zero_readfile_thread_proc,
12151216
req,
12161217
WT_EXECUTELONGFUNCTION)) {
1218+
if (handle->readfile_mutex)
1219+
uv_mutex_unlock(handle->readfile_mutex);
12171220
/* Make this req pending reporting an error. */
12181221
SET_REQ_ERROR(req, GetLastError());
12191222
goto error;

0 commit comments

Comments
 (0)