[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libmicrohttpd] MHD_stop_daemon occasionally locks on pthread_join

From: Lorenzo Miniero
Subject: [libmicrohttpd] MHD_stop_daemon occasionally locks on pthread_join
Date: Wed, 30 Apr 2014 16:37:07 +0200


from time to time, when I close my application using libmicrohttpd (SIGINT is intercepted for a cleanup), the code gets stuck on MHD_stop_daemon and only leaves if I wait long enough (last time 5 minutes, I don't know if there's an explicit timeout involved here), unless I terminate it.

Using gdb to attach to the main pid, I can see that the cause is the pthread_join called by close_all_connections that apparently never returns. I'm attaching the whole stack trace for your interest:

#0  0x00000035c1008e60 in pthread_join (threadid=139782655043328, 
    address@hidden) at pthread_join.c:92
#1  0x00007f21db491c89 in close_all_connections (address@hidden)
    at daemon.c:3916
#2  0x00007f21db494e90 in MHD_stop_daemon (daemon=0x7e5300) at daemon.c:4064
#3  0x000000000040efb9 in main (argc=1, argv=0x7ffffb6c1008) at janus.c:1844

All the times it happened, there was actually no connection pending on the server, as the cleanup was done when the server wasn't serving any request anymore. That said, attaching to the other pids still up, I could find another one related to MHD, where the backtrace seemed to indicate there still was a thread serving a connection that wasn't there anymore, and that was waiting on a poll():

#0  0x00000035c0ce9a5d in poll () at ../sysdeps/unix/syscall-template.S:81
#1  0x00007f91faf19d49 in poll (__timeout=<optimized out>, __nfds=1, __fds=
    0x7f91c3ffec60) at /usr/include/bits/poll2.h:46
#2  MHD_handle_connection (data="" at daemon.c:803
#3  0x00000035c1007d15 in start_thread (arg=0x7f91c3fff700)
    at pthread_create.c:308
#4  0x00000035c0cf253d in clone ()
    at ../sysdeps/unix/sysv/linux/x86_64/clone.S:114

What could be the cause? I guess that one of the threads serving the connections (MHD_USE_THREAD_PER_CONNECTION is used in my case) was still alive, but as I anticipated there's actually no request pending anymore, and all the tabs in the browser were closed as well, which should have closed the Ajax requests I use to contact the MHD-based server. What may be causing the poll to get stuck all that time, and how can I force it to unblock? EINTR can't be used as it is intercepted by the code, and a continue is issued without checking whether the webserver is closing or not. I'm using 0.9.33 by the way, not sure whether this was already fixed in 0.9.34 or not.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]