View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0004641 | libmicrohttpd | other | public | 2016-09-05 15:41 | 2016-10-17 19:21 |
Reporter | Hawk | Assigned To | Christian Grothoff | ||
Priority | high | Severity | major | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | MINGW | OS | WINDOWS | OS Version | 10 PRO |
Product Version | 0.9.51 | ||||
Target Version | 0.9.52 | Fixed in Version | 0.9.52 | ||
Summary | 0004641: libmicrohttpd 0.9.51 use 100% of the cpu | ||||
Description | Hello, If I use libmicrohttpd with MHD_USE_THREAD_PER_CONNECTION and MHD_USE_POLL, after a while libmicrohttpd use 100% of the cpu | ||||
Additional Information | If I add : printf("HERE WITH REVENT=%04x\n", p[1].revents); after MHD_sys_poll_ in MHD_handle_connection (daemon.c file), my sample application display : HERE WITH REVENT=0100 HERE WITH REVENT=0100 HERE WITH REVENT=0100 ... The pipe seems to be never read and MHD_sys_poll return immediately.. if I modify : /* drain signaling pipe before other processing */ if ( (MHD_INVALID_PIPE_ != spipe) && (0 != (p[1].revents & (POLLERR | POLLHUP))) ) MHD_pipe_drain_ (spipe); to /* drain signaling pipe before other processing */ if ( (MHD_INVALID_PIPE_ != spipe) && (0 != (p[1].revents & (POLLERR | POLLHUP | POLLIN))) ) MHD_pipe_drain_ (spipe); libmicrohttd use 100% cpu only after a period of inactivity. I a open a new connection libmicrohttpd use again 0% cpu time (with this patch). I have no issue with libmicrohttpd 0.9.50 | ||||
Tags | No tags attached. | ||||
|
The patch certainly looks right to me (committed as SVN 37898), but I don't understand what is going on if you say that you do see 100% CPU even with the patch. Could you give use some hint where the code is stuck in a loop, or provide a test? (I don't use W32, so Evgeny is the right person to look into this.) |
|
I found the problem : libmicrohttpd 0.9.51 has add : /* if we were at the connection limit before and are in thread-per-connection mode, signal the main thread to resume accepting connections */ if ( (0 != (daemon->options & MHD_USE_THREAD_PER_CONNECTION)) && (MHD_INVALID_PIPE_ != daemon->wpipe[1]) && (1 != MHD_pipe_write_ (daemon->wpipe[1], "c", 1)) ) { #ifdef HAVE_MESSAGES MHD_DLOG (daemon, "failed to signal end of connection via pipe"); #endif } in MHD_connection_close_ function (src/microhttpd/connection.c) To correct "100% CPU usage" you must also commit this patch : ------------------------------------------------------------------- --- ../libmicrohttpd-0.9.51/src/microhttpd/daemon.c_ori 2016-09-07 13:27:11.000000000 +0200 +++ ../libmicrohttpd-0.9.51/src/microhttpd/daemon.c 2016-09-07 13:26:45.000000000 +0200 @@ -2511,9 +2511,11 @@ int timeout; unsigned int poll_count; int poll_listen; + int poll_pipe; memset (&p, 0, sizeof (p)); poll_count = 0; poll_listen = -1; + poll_pipe = -1; if (MHD_INVALID_SOCKET != daemon->socket_fd) { p[poll_count].fd = daemon->socket_fd; @@ -2527,6 +2529,7 @@ p[poll_count].fd = daemon->wpipe[0]; p[poll_count].events = POLLIN; p[poll_count].revents = 0; + poll_pipe = poll_count; poll_count++; } if (MHD_NO == may_block) @@ -2547,6 +2550,11 @@ #endif return MHD_NO; } + + if ( (-1 != poll_pipe) && + (0 != (p[poll_pipe].revents & POLLIN)) ) + MHD_pipe_drain_ (daemon->wpipe[0]); + /* handle shutdown */ if (MHD_YES == daemon->shutdown) return MHD_NO; ------------------------------------------------------------------- |
|
the second patch probably affect also Linux |
|
Fixed as suggested in SVN 37903. |
Date Modified | Username | Field | Change |
---|---|---|---|
2016-09-05 15:41 | Hawk | New Issue | |
2016-09-06 23:01 | Christian Grothoff | Note Added: 0011093 | |
2016-09-06 23:01 | Christian Grothoff | Assigned To | => Karlson2k |
2016-09-06 23:01 | Christian Grothoff | Status | new => assigned |
2016-09-07 12:34 | Hawk | Note Added: 0011097 | |
2016-09-07 12:37 | Hawk | Note Added: 0011098 | |
2016-09-07 13:22 | Christian Grothoff | Note Added: 0011099 | |
2016-09-07 13:22 | Christian Grothoff | Status | assigned => resolved |
2016-09-07 13:22 | Christian Grothoff | Fixed in Version | => 0.9.52 |
2016-09-07 13:22 | Christian Grothoff | Resolution | open => fixed |
2016-09-07 13:22 | Christian Grothoff | Assigned To | Karlson2k => Christian Grothoff |
2016-09-07 13:22 | Christian Grothoff | Target Version | => 0.9.52 |
2016-10-17 19:21 | Christian Grothoff | Status | resolved => closed |