Home > Software design >  web server returns "broken pipe" error when constantly reloading page
web server returns "broken pipe" error when constantly reloading page

Time:10-28

I found a partial solution for the last couple errors and what I did was just create a thread pool instead of creating new threads and killing them each connection. Now i don't have those weird errors but I am having a problem listed below.

I'm working on a C web server on my raspberry pi and i'm able to handle multiple web page requests but when the client decides to reload the page really fast, after a couple of reloads, the web server crashes and gdb gives me the error: "broken pipe".

Here's the code for the server: https://hastebin.com/wuzepotiko.c

I think the problem might be with the read error handling because when I use gdb it gives me the error:

Thread 13 "webServer" received signal SIGPIPE, Broken pipe.
[Switching to Thread 0xb161f440 (LWP 23260)]
__libc_write (nbytes=0, buf=0x22cc0 <httpResponse>, fd=7)
    at ../sysdeps/unix/sysv/linux/write.c:26
26  ../sysdeps/unix/sysv/linux/write.c: No such file or directory.

I know it's a ton of code but I've been stuck on this for a while now. Even if someone could point me in the right direction I would really appreciate it!

CodePudding user response:

I found an answer to the question. Since the write function was sending a broken pipe error to the kernel, which told the kernel to quit the process, i used the send function which allowed me to prevent signals being sent to the kernel and now it works! Thank you to everyone who helped me fix my problems!

  • Related