khttpd problems

khttpd, the first http accellerator built into the Linux kernel, is very fast, especially at serving small files. However, it appears to have some stability problems. It is fairly easy to cause a server running khttpd on some versions of linux to crash.

As of 2.4.17, it looks like you have to run with only 1 thread, and avoid quickly cycling it up and down, to have any hope of stability -- and even then, abruptly terminating client connections causes an oops fairly frequently.

In 2.4.17, in my initial testing with khttpd, I couldn't fetch .http files from khttpd because DecodeHeader was getting -EFAULT back from sock_recvmsg! Here's the scenario:

  1. khttpd starts. InitWaitHeaders is called, which allocates Buffer[] in waitheaders.c.
  2. Operator stops khttpd. StopWaitingForHeaders is called, which frees Buffer[] in waitheaders.c.
  3. Operator restarts khttpd. *InitWaitHeaders is not called again*. When WaitForHeaders gets a header, it calls DecodeHeader, which calls sock_recvmsg with Buffer[] as a buffer, which causes an EFAULT as the buffer has not been allocated.
This same problem can be triggered by bringing khttpd up and down in a loop. Here's a test script to do that, and a not-very-enlightening crash traceback.

Another minor problem was found by the Stanford checker: a value that cannot be NULL was being checked against NULL.

Patches

Here are patches to fix up khttpd: I submitted the first of these to khttpd-users, but have not asked Marcello to apply the to the 2.4 kernel. I probably should.