boazsegev / facil.io

Your high performance web application C framework
http://facil.io
MIT License
2.11k stars 139 forks source link

Timeout issue when sending large files in the public_folder and over http_sendfile #154

Open Ortmanns-Koeppern opened 2 months ago

Ortmanns-Koeppern commented 2 months ago

Problem

When sending files either by downloading them from the public folder as well as using the http_sendfile2 function, the timeout still applies to the request and cancels it if the download takes longer than the timeout allows.

Solutions/Workarounds

Although this problem can be mitigated by setting the timeout in general or the timeout for the specific request to a long duration, this solution can still cause problems because it would not dynamically adapt to the bandwidth of different clients. Another solution could be to use fio_touch, but I did not implement a working example for this approach.

Setup

Running fio with (could add the long timeout for the mentioned solution)

// listen on port 3000 and any available network binding (NULL == 0.0.0.0)
http_listen("3000", NULL,
            .on_request = on_request,
            .on_upgrade = on_http_upgrade,
            .log = loglevel,
            .public_folder = public_folder);
// start the server
fio_start(.threads = 2);

Sending files with this function

char *p = "testfile.bin";
// http_s *req
if(http_sendfile2(req, p, strlen(p), NULL, 0)) {
  http_send_error(req, 404);
  FIO_LOG_WARNING("Can't read file %s", p);
  return 1;
}

Notes

I am not that experienced with the library. If i missed any functionality or setup to solve this problem please let me know.

boazsegev commented 2 months ago

Hi,

Thank you for opening this issue.

I am currently busy working on the 0.8.0 version and it took me a while to notice this thread, sorry about that.

I am unsure as what would cause this issue. How big is the file you're sending? I will try on my machine.

Also, could you please try this on your local machine with throttling on the browser?

I suspect this might be a "slow client" issue, where the buffer is full and awaiting a client to read from the buffer.

Thanks, B.