Hello.

I'm playing with libuv and have this code [1]. This is, basically, just UDP 
echo server which replies with "hello" on every request.

The workflow is as follows: UDP packet arrives, in on_read callback new 
work is queued via uv_queue_work() (line 138), and in this 
"work" uv_udp_send() is being used to send a reply (line 92). There are 4 
separate loops shown in my example, working using SO_REUSEPORT, but I face 
the issue with single loop as well.

The issue is that occasionally and randomly I face either segfault:

===
Thread 2 "test_uv" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6fb2700 (LWP 25053)]
uv__count_bufs (bufs=0x0, nbufs=1) at src/uv-common.c:431
431         bytes += (size_t) bufs[i].len;
(gdb) bt
#0  uv__count_bufs (bufs=0x0, nbufs=1) at src/uv-common.c:431
#1  0x00007ffff7bcb6b8 in uv__udp_run_completed 
(handle=handle@entry=0x603028) at src/unix/udp.c:102
#2  0x00007ffff7bcba40 in uv__udp_io (loop=<optimized out>, w=0x6030a8, 
revents=<optimized out>) at src/unix/udp.c:143
#3  0x00007ffff7bcd7c5 in uv__io_poll (loop=loop@entry=0x7ffff00008c0, 
timeout=-1) at src/unix/linux-core.c:345
#4  0x00007ffff7bbff17 in uv_run (loop=0x7ffff00008c0, mode=UV_RUN_DEFAULT) 
at src/unix/core.c:341
#5  0x00000000004014e8 in dnsb_dwrk (_data=0x603010) at test_uv.c:182
#6  0x00007ffff7bca437 in uv__thread_start (arg=<optimized out>) at 
src/unix/thread.c:49
#7  0x00007ffff77995ca in start_thread (arg=0x7ffff6fb2700) at 
pthread_create.c:333
#8  0x00007ffff70b60ed in clone () at 
../sysdeps/unix/sysv/linux/x86_64/clone.S:109
(gdb) l
426       unsigned int i;
427       size_t bytes;
428
429       bytes = 0;
430       for (i = 0; i < nbufs; i++)
431         bytes += (size_t) bufs[i].len;
432
433       return bytes;
434     }
435
===

or failed assertion:

===
test_uv: src/unix/udp.c:103: uv__udp_run_completed: Assertion 
`uv__has_active_reqs(handle->loop)' failed.
===

Backtrace above is for libuv v1.7.5 found in Fedora 24, and assertion 
failed message is from v1.10.2 found in Arch Linux.

The issue is triggered not instantly, but after some time. I have to send 
lots of UDP packets to this echo server to trigger the issue. So, this 
looks like race condition or improper usage of libuv by me without proper 
locking.

My questions are:

1) is there some libuv improper usage in my example that could lead to 
occasional crash?
2) if not, could you please help me to debug this issue further and fill a 
bugreport properly, or if there are some devs, how could I help you to fix 
this behavior?
3) if yes, IOW, if I use libuv incorrectly, how should I fix my code?

Thanks.

[1] https://gist.github.com/pfactum/5b621b55ffc053791227c9c3c66377a8

-- 
You received this message because you are subscribed to the Google Groups 
"libuv" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/libuv.
For more options, visit https://groups.google.com/d/optout.

Reply via email to