View Issue Details

IDProjectCategoryView StatusLast Update
0002085libmicrohttpdexternal even looppublic2012-01-23 14:21
Reportertclaveirole Assigned ToChristian Grothoff  
PrioritynormalSeverityminorReproducibilitysometimes
Status closedResolutionfixed 
Product Version0.9.17 
Target Version0.9.18Fixed in Version0.9.18 
Summary0002085: MHD_get_timeout relies on uninitialized variable, leads to busy waiting sometimes
DescriptionThe earliest_deadline variable in MHD_get_timeout (src/daemon/daemon.c, line 1204) is not initialized. Therefore, the comparison on line 1223 is invalid. On some occasions (e.g., earliest_deadline's first value is zero), this leads to returning an incorrect timeout. Sometimes this incorrect timeout is constantly zero and the HTTP server starts busy waiting.
Steps To ReproduceBecause this bug depends on the state of an uninitialized variable, it is sometimes hard to reproduce. Here are steps that triggers the bug every time on my machine (Debian i386 testing, with Debian GCC 4.6.2-11).

1. Use a libmicrohttpd that has optimizations disabled (i.e., compiled with -O0. Else the uninitialized variable goes into a register and the result is unpredictable).

2. Compile and run the attached test.c. This is a simple HTTP server that uses libmicrohttpd with external select and connection timeouts. Each time MHD_get_timeout returns a valid timeout with value 0, the server prints a '.' character. The server never replies to requests (so it should close HTTP connections abruptly when their timeouts expire).

3. Make a request to the server. The server then busy waits: it prints a lot of '.' until the timeout is reached and the connection closed. At this point, it goes back to using select() with no timeout. This is not the expected behavior. As nothing is done to reply to the request, the server should have spent most of its time blocked in select() with a proper timeout.
Additional InformationAttached is a patch that solves that bug.
TagsNo tags attached.
Attached Files
attachments.tar (10,240 bytes)

Relationships

related to 0002018 closedChristian Grothoff GNUnet http(s) transport eats cpu 

Activities

Christian Grothoff

2012-01-19 17:47

manager   ~0005296

Fixed in SVN 19263.

Issue History

Date Modified Username Field Change
2012-01-19 15:38 tclaveirole New Issue
2012-01-19 15:38 tclaveirole File Added: attachments.tar
2012-01-19 17:33 Christian Grothoff Target Version => 0.9.18
2012-01-19 17:34 Christian Grothoff Assigned To => Christian Grothoff
2012-01-19 17:34 Christian Grothoff Status new => assigned
2012-01-19 17:47 Christian Grothoff Note Added: 0005296
2012-01-19 17:47 Christian Grothoff Status assigned => resolved
2012-01-19 17:47 Christian Grothoff Fixed in Version => 0.9.18
2012-01-19 17:47 Christian Grothoff Resolution open => fixed
2012-01-19 22:21 Christian Grothoff Relationship added related to 0002018
2012-01-23 14:21 Christian Grothoff Status resolved => closed
2013-05-06 12:52 Christian Grothoff Category external select => libmicrohttpd external select
2024-01-21 13:24 Christian Grothoff Category libmicrohttpd external select => external even loop