Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 327615 - www-servers/thttpd-2.25b-r7: Setting clock backwards hangs a web-server
Summary: www-servers/thttpd-2.25b-r7: Setting clock backwards hangs a web-server
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Server (show other bugs)
Hardware: All All
: High normal (vote)
Assignee: www-servers Herd (OBSOLETE)
URL:
Whiteboard:
Keywords:
Depends on: 331747
Blocks:
  Show dependency tree
 
Reported: 2010-07-09 12:53 UTC by Mikhail Zolotaryov
Modified: 2011-01-13 20:03 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
Patch to use monotonic time (thttpd-2.25b-timer.patch,8.40 KB, patch)
2010-07-09 12:56 UTC, Mikhail Zolotaryov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mikhail Zolotaryov 2010-07-09 12:53:30 UTC
Setting clock backwards may lead to the unexpected thttpd termination.

Reproducible: Always

Steps to Reproduce:
1) start thttpd daemon (start-up options don't matter);
2) set the system clock 10 minutes back;
3) do nothing for about 6 minutes;
4) thttpd will terminate without a log message.

The bug appears in early program versions as well:
http://www.mail-archive.com/php-general@lists.php.net/msg174036.html 

Actual Results:  
The web-server daemon terminates.

Expected Results:  
The web-server should keep working stable.

Reasons.

The software utilizes system time to implement a number of internal timers for:
- internal watchdog;
- periodic file mmap cache expiration check;
- periodic idle connections closing;
- periodic average rate updates for throttles;
- periodic statistics displaying;
- connections "wake-up" (recovery);
- lingering connections closing;
- CGI execution time limit implementation (CGI_TIMELIMIT).

So the problem is a scheduled time is no longer valid after system time changing. For example, current time is 15:00 and thttpd schedules some timer to expire in 5 minutes i.e. at 15:05, then system time changes (DST, manual adjusting by user / NTP cron script). As a result, one of the following happens:
1) all active timers expire too late, if system time went backwards;
2) all active timers expire too early (even immediately), if system time went forward.

In the first case, if a watchdog handler is not called within appropriate period, the program calls abort() (thttpd.c:handle_alrm()) to go out of hang state (as it's supposed to happen). Other negative consequences (normal operation interruption) are also possible.
Comment 1 Mikhail Zolotaryov 2010-07-09 12:56:12 UTC
Created attachment 238121 [details, diff]
Patch to use monotonic time

The patch attached checks for MONOTONIC clock availability and uses it for timers expiration evaluation instead of system time. This includes both compile-time check (for the clock access function availability) and run-time check (to ensure that monotonic clock time is fetchable).
Is friendly to cross-compiling.

Notes: an ideal solution should completely re-write thttpd to POSIX timers.
Comment 2 Thilo Bangert (RETIRED) (RETIRED) gentoo-dev 2010-08-09 10:49:10 UTC
sorry, but thttpd is really not maintained in gentoo - and hasnt been in a long time. i have proposed it for removal. see bug 331747

thanks
Comment 3 Thilo Bangert (RETIRED) (RETIRED) gentoo-dev 2010-10-28 22:26:37 UTC
fixed in -r8.
Comment 4 Nishant 2011-01-13 20:03:07 UTC
(In reply to comment #3)
> fixed in -r8.

Hi,

I am also facing the same issue.

I have applied your patch but problem is still exists.

Can you send me the link to download -r8 version of thttpd2.25b

Thanks and Regards,

Nishant Joshi