test-ipc-heavy-traffic-deadlock-bug.c
Go to the documentation of this file.
1 /* Copyright libuv project contributors. All rights reserved.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to
5  * deal in the Software without restriction, including without limitation the
6  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7  * sell copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19  * IN THE SOFTWARE.
20  */
21 
22 #include "task.h"
23 #include "uv.h"
24 
25 #include <string.h>
26 
27 /* See test-ipc.c */
30  const char* helper);
31 
32 #define NUM_WRITES 256
33 #define BUFFERS_PER_WRITE 3
34 #define BUFFER_SIZE 0x2000 /* 8 kb. */
35 #define BUFFER_CONTENT 42
36 
37 #define XFER_SIZE (NUM_WRITES * BUFFERS_PER_WRITE * BUFFER_SIZE)
38 
39 struct write_info {
42 };
43 
45 
46 static size_t bytes_written;
47 static size_t bytes_read;
48 
49 static void write_cb(uv_write_t* req, int status) {
50  struct write_info* write_info =
52  ASSERT(status == 0);
54  free(write_info);
55 }
56 
57 static void shutdown_cb(uv_shutdown_t* req, int status) {
58  ASSERT(status == 0 || status == UV_ENOTCONN);
59  uv_close((uv_handle_t*) req->handle, NULL);
60 }
61 
62 static void do_write(uv_stream_t* handle) {
63  struct write_info* write_info;
65  size_t i;
66  int r;
67 
68  write_info = malloc(sizeof *write_info);
69  ASSERT(write_info != NULL);
70 
71  for (i = 0; i < BUFFERS_PER_WRITE; i++) {
74  }
75 
76  r = uv_write(
78  ASSERT(r == 0);
79 }
80 
82  size_t suggested_size,
83  uv_buf_t* buf) {
84  buf->base = malloc(suggested_size);
85  buf->len = (int) suggested_size;
86 }
87 
88 #ifndef _WIN32
89 #include <sys/types.h>
90 #include <unistd.h>
91 #endif
92 
93 static void read_cb(uv_stream_t* handle, ssize_t nread, const uv_buf_t* buf) {
94  ssize_t i;
95  int r;
96 
97  ASSERT(nread >= 0);
98  bytes_read += nread;
99 
100  for (i = 0; i < nread; i++)
101  ASSERT(buf->base[i] == BUFFER_CONTENT);
102  free(buf->base);
103 
104  if (bytes_read >= XFER_SIZE) {
105  r = uv_read_stop(handle);
106  ASSERT(r == 0);
108  ASSERT(r == 0);
109  }
110 }
111 
113  size_t i;
114  int r;
115 
116  bytes_written = 0;
117  bytes_read = 0;
118 
119  for (i = 0; i < NUM_WRITES; i++) {
120  do_write(handle);
121  }
122 
124  ASSERT(r == 0);
125 
126  r = uv_run(handle->loop, UV_RUN_DEFAULT);
127  ASSERT(r == 0);
128 
131 }
132 
133 TEST_IMPL(ipc_heavy_traffic_deadlock_bug) {
134  uv_pipe_t pipe;
136 
137  spawn_helper(&pipe, &process, "ipc_helper_heavy_traffic_deadlock_bug");
139 
141  return 0;
142 }
143 
145  uv_pipe_t pipe;
146  int r;
147 
148  r = uv_pipe_init(uv_default_loop(), &pipe, 1);
149  ASSERT(r == 0);
150  r = uv_pipe_open(&pipe, 0);
151  ASSERT(r == 0);
152 
155  uv_sleep(100);
156 
158  return 0;
159 }
write_info::write_req
uv_write_t write_req
Definition: test-ipc-heavy-traffic-deadlock-bug.c:40
BUFFERS_PER_WRITE
#define BUFFERS_PER_WRITE
Definition: test-ipc-heavy-traffic-deadlock-bug.c:33
uv_process_s
Definition: uv.h:1037
BUFFER_SIZE
#define BUFFER_SIZE
Definition: test-ipc-heavy-traffic-deadlock-bug.c:34
alloc_cb
static void alloc_cb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:81
task.h
memset
return memset(p, 0, total)
uv_pipe_init
UV_EXTERN int uv_pipe_init(uv_loop_t *, uv_pipe_t *handle, int ipc)
Definition: unix/pipe.c:33
BUFFER_CONTENT
#define BUFFER_CONTENT
Definition: test-ipc-heavy-traffic-deadlock-bug.c:35
shutdown_req
static uv_shutdown_t shutdown_req
Definition: test-ipc-heavy-traffic-deadlock-bug.c:44
uv_shutdown_s
Definition: uv.h:417
string.h
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
uv_connect_s::handle
uv_stream_t * handle
Definition: uv.h:583
ASSERT
#define ASSERT(expr)
Definition: task.h:102
status
absl::Status status
Definition: rls.cc:251
write_req
Definition: benchmark-tcp-write-batch.c:31
uv_run
UV_EXTERN int uv_run(uv_loop_t *, uv_run_mode mode)
Definition: unix/core.c:361
container_of
#define container_of(ptr, type, member)
Definition: uv-common.h:57
do_writes_and_reads
static void do_writes_and_reads(uv_stream_t *handle)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:112
uv_close
UV_EXTERN void uv_close(uv_handle_t *handle, uv_close_cb close_cb)
Definition: unix/core.c:112
shutdown_cb
static void shutdown_cb(uv_shutdown_t *req, int status)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:57
uv_stream_s
Definition: uv.h:491
uv_default_loop
UV_EXTERN uv_loop_t * uv_default_loop(void)
Definition: uv-common.c:733
channel
wrapped_grpc_channel * channel
Definition: src/php/ext/grpc/call.h:33
read_cb
static void read_cb(uv_stream_t *handle, ssize_t nread, const uv_buf_t *buf)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:93
ssize_t
intptr_t ssize_t
Definition: win.h:27
process
static uv_process_t process
Definition: benchmark-spawn.c:32
xds_interop_client.int
int
Definition: xds_interop_client.py:113
uv_write
UV_EXTERN int uv_write(uv_write_t *req, uv_stream_t *handle, const uv_buf_t bufs[], unsigned int nbufs, uv_write_cb cb)
Definition: unix/stream.c:1492
req
static uv_connect_t req
Definition: test-connection-fail.c:30
UV_RUN_DEFAULT
@ UV_RUN_DEFAULT
Definition: uv.h:254
uv_shutdown
UV_PRIVATE_REQ_TYPES UV_EXTERN int uv_shutdown(uv_shutdown_t *req, uv_stream_t *handle, uv_shutdown_cb cb)
Definition: unix/stream.c:1259
bytes_read
static size_t bytes_read
Definition: test-ipc-heavy-traffic-deadlock-bug.c:47
uv_read_start
UV_EXTERN int uv_read_start(uv_stream_t *, uv_alloc_cb alloc_cb, uv_read_cb read_cb)
Definition: unix/stream.c:1555
do_write
static void do_write(uv_stream_t *handle)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:62
uv_sleep
UV_EXTERN void uv_sleep(unsigned int msec)
Definition: unix/core.c:1521
TEST_IMPL
TEST_IMPL(ipc_heavy_traffic_deadlock_bug)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:133
notify_parent_process
void notify_parent_process(void)
Definition: runner-unix.c:54
write_info::buffers
char buffers[BUFFER_SIZE][BUFFERS_PER_WRITE]
Definition: test-ipc-heavy-traffic-deadlock-bug.c:41
bufs
static uv_buf_t bufs[5]
Definition: benchmark-udp-pummel.c:51
uv.h
MAKE_VALGRIND_HAPPY
#define MAKE_VALGRIND_HAPPY()
Definition: task.h:229
uv_buf_t
Definition: unix.h:121
spawn_helper
void spawn_helper(uv_pipe_t *channel, uv_process_t *process, const char *helper)
Definition: test-ipc.c:291
NUM_WRITES
#define NUM_WRITES
Definition: test-ipc-heavy-traffic-deadlock-bug.c:32
fix_build_deps.r
r
Definition: fix_build_deps.py:491
uv_pipe_s
Definition: uv.h:757
uv_buf_init
UV_EXTERN uv_buf_t uv_buf_init(char *base, unsigned int len)
Definition: uv-common.c:157
XFER_SIZE
#define XFER_SIZE
Definition: test-ipc-heavy-traffic-deadlock-bug.c:37
uv_write_s
Definition: uv.h:522
handle
static csh handle
Definition: test_arm_regression.c:16
bytes_written
static size_t bytes_written
Definition: test-ipc-heavy-traffic-deadlock-bug.c:46
uv_handle_s
Definition: uv.h:441
write_info
Definition: test-ipc-heavy-traffic-deadlock-bug.c:39
uv_read_stop
UV_EXTERN int uv_read_stop(uv_stream_t *)
Definition: unix/stream.c:1590
write_cb
static void write_cb(uv_write_t *req, int status)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:49
uv_pipe_open
UV_EXTERN int uv_pipe_open(uv_pipe_t *, uv_file file)
Definition: unix/pipe.c:137
ipc_helper_heavy_traffic_deadlock_bug
int ipc_helper_heavy_traffic_deadlock_bug(void)
Definition: test-ipc-heavy-traffic-deadlock-bug.c:144
i
uint64_t i
Definition: abseil-cpp/absl/container/btree_benchmark.cc:230


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:26