Search code examples
cnetwork-programmingrouteropenwrtuclibc

C http server stops after unpredictable time


I am writing a custom HTTP server in C for my OpenWrt router. It makes use of the uclibc library. I am only using one static buffer which I am very careful not to overflow, and no multi-threading is involved. It doesn't contain any complex data structures, and what it does is that:

  • it listen() s on the socket
  • reads the request after accept() ing
  • gets an html page by sending an http request to a predefined remote server (not a proxy)
  • sends the result through the accepted connection, and closes both.

The program would just stop running after some time, (it can be on receiving the first request, or after working under heavy strain for more that 2 hours). I am getting no error messages through the console, or anything, the program just stops. I have watched it and, as expected it doesn't consume more and more memory as it runs...

  • Is it possible that the kernel stops it if it thinks its abusing the CPU? How do I overcome that?
  • Are there some quirks to watch for in socket programming in C that are known to cause such crashes?
  • Can the stability issues be caused by using the Barrier Bracker (bleeding edge) branch of OpenWrt? Although the router itself never stops working...

Where do I start to look for the source of the problem?


Solution

  • Ok, first, I would like to thank everybody for helping. After writing a lot of netcat testers, I have pinpointed the problem. The program would crash - end without a single error message, if the connection is closed by the client before the last write or read occurs. The write or read would raise a SIGPIPE signal which by default crashed the program if not handled manually... More info here: How to prevent SIGPIPE or prevent the server from ending?