eddic / fastcgipp

fastcgi++: A C++ FastCGI and Web development platform:
https://fastcgipp.isatec.ca
GNU Lesser General Public License v3.0
310 stars 94 forks source link

File Uploads larger than ~500kb causes Read() error behind nginx #17

Closed samlauzon closed 7 years ago

samlauzon commented 7 years ago

Was getting a "Socket read() error on fd 8: Resource temporarily unavailable" when uploading files larger than ~500kb using the library being an nginx proxy. (nginx throws a 502 to the client and "writev() failed (32: Broken pipe) while sending request to upstream" to the error log)

Adding a hacky retry loop that's around the read call (socket.cpp:74 - commit fc9bfc4) seems to fix the issue for my purposes (can upload 20mb+ now) - but I didn't track down the underlying cause.

Hope this helps, Cheers

eddic commented 7 years ago

So I can't reproduce this nor find your fork. Any more info?

samlauzon commented 7 years ago

Apologies - should have put some more info in for replication;

It was a straight build of commit d39ea6d9836f502753266725bd8392d99785d9ce with the echo example doing a file upload with multipart/form-data. (It's been a while.)

I've got it running now on https://mu.uptane.org/ (2017-04-27 23:37 GMT) for the next few hours without the patch. If you upload over 500k, you'll see the server 'disappear' and a custom 502 show up.

Refresh and the page reloads fine, same thread, etc.

stderr shows Apr 27 19:33:40 uptane.org ./a.out[15963] [warning]: Socket read() error on fd 7: Resource temporarily unavailable

Patch I wrote that was rectifying the issue; https://gist.github.com/samlauzon/1c8b65b6d95ca98f7b7cec21c51a6e85

eddic commented 7 years ago

Hmmm Interesting. I'm just wondering if anyone has seen similar issues. I don't have an nginx server but I can't reproduce with lighttpd or apache. Have you tried it with a separate nginx install?

eddic commented 7 years ago

Ah you know. I think I may have reproduced it.

eddic commented 7 years ago

Alrighty. Can you see if ced61e45 fixes it? After try out the master head and see if it still works (or is fixed) as some other big changes came after.

samlauzon commented 7 years ago

Sorry about the delay, pulled the latest and built the echo example; File uploading now outputs:

/a.out[31136] [warning]: Got a non BEGIN_REQUEST record for a request that doesn't exist (x10) ./a.out[31136] [warning]: Socket read() error on fd 7: Resource temporarily unavailable

samlauzon commented 7 years ago

At last - I was able to make this work; had to ensure buffering was off in nginx. Thanks!