forked from libuv/libuv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
win, pipe: avoid synchronous pipe deadlocks
Add a thread that will interrupt uv_pipe_zero_readdile_thread_proc every half second. This allows other processes to access the pipe without deadlocking Ref: nodejs/node#10836
- Loading branch information
Showing
4 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include "uv.h" | ||
#include "task.h" | ||
|
||
#ifndef _WIN32 | ||
TEST_IMPL(pipe_open_read_pipe) { | ||
RETURN_SKIP("Test only for Windows."); | ||
} | ||
#else | ||
|
||
#define NAME_BUF_SIZE 32768 | ||
#define CHILD_WAIT_TIMEOUT 1000 | ||
|
||
void alloc_cb(uv_handle_t* handle, size_t suggested_size, uv_buf_t* buf) { | ||
buf->base = malloc(suggested_size); | ||
buf->len = suggested_size; | ||
} | ||
|
||
void read_cb(uv_stream_t* stream, ssize_t nread, const uv_buf_t* buf) { | ||
} | ||
|
||
void pipe_read_thread_proc(void* arg) { | ||
uv_pipe_t* pipe = arg; | ||
uv_read_start(pipe, alloc_cb, read_cb); | ||
uv_run(uv_default_loop(), UV_RUN_DEFAULT); | ||
FATAL("loop should not exit"); | ||
} | ||
|
||
TEST_IMPL(pipe_open_read_pipe) { | ||
int r, pipe_fd; | ||
uv_thread_t pipe_read_thread; | ||
uv_pipe_t uv_pipe, uv_reopen_pipe; | ||
HANDLE stdin_read_pipe, stdin_write_pipe; | ||
SECURITY_ATTRIBUTES sa_attr; | ||
|
||
sa_attr.nLength = sizeof(SECURITY_ATTRIBUTES); | ||
sa_attr.bInheritHandle = TRUE; | ||
sa_attr.lpSecurityDescriptor = NULL; | ||
r = CreatePipe(&stdin_read_pipe, &stdin_write_pipe, &sa_attr, 0); | ||
ASSERT(r != 0); | ||
|
||
r = uv_pipe_init(uv_default_loop(), &uv_pipe, 0); | ||
ASSERT(r == 0); | ||
pipe_fd = _open_osfhandle(stdin_read_pipe, 0); | ||
r = uv_pipe_open(&uv_pipe, pipe_fd); | ||
ASSERT(r == 0); | ||
|
||
r = uv_thread_create(&pipe_read_thread, pipe_read_thread_proc, &uv_pipe); | ||
ASSERT(r == 0); | ||
|
||
/* Give uv_run some time to start */ | ||
uv_sleep(250); | ||
/* Try to access the pipe again, in different loop */ | ||
uv_loop_t test_loop; | ||
r = uv_loop_init(&test_loop); | ||
ASSERT(r == 0); | ||
r = uv_pipe_init(&test_loop, &uv_reopen_pipe, 0); | ||
ASSERT(r == 0); | ||
r = uv_pipe_open(&uv_reopen_pipe, pipe_fd); | ||
return TEST_OK; | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters