ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.73k stars 518 forks source link

ring-jetty and timeouts #473

Closed mooseyboots closed 1 year ago

mooseyboots commented 1 year ago

i'm a clj beginner working on a learning/hobby project and having trouble with requests to my app timing out.

the app allows you to upload a PDF, the server OCR scans it, and returns it for download. i'm only running it locally.

it works with small files (< 1mb), but with larger files (> 1mb) the request drops out (with no error message in the browser, nothing happens except the request stops). the timing of the drop out is irregular, it's not always 30 or 60 secs. after the drop out, the clojure function completes the OCR scanning as normal.

i'm running jetty in a -main function with the ring-jetty adapter and with options like so:

(jetty/run-jetty app
{:port 3000
  :max-idle-time 12000000
  :thread-idle-timeout 60000000
  :request-header-size 819200}

i.e. with very large values to see if this would help it hang on, but to no avail.

i also tried using JS Ajax to send async requests, and to my surprise they also do not work with my larger test file, but do with the smaller one.

is there anything i can do to get around this? i'm a little lost, especially since failing to solve it via async requests, so any pointers would be appreciated.

(as it is an amateur project i wouldn't mind a long hanging request, at least until i learn more and re-write it. i have done as much with another flask app by setting nginx timeouts to large values.)

mooseyboots commented 1 year ago

i also tried out file upload requests via curl, and the large files worked, and returned, with no problem.

weavejester commented 1 year ago

When the request "stops", does the connection close? How are you handling the upload? If this is a learning/hobby project, are you able to provide source code or a working example so the behaviour can be reproduced?

mooseyboots commented 1 year ago

the code is here: https://codeberg.org/martianh/ocrpdf-web.

i'm don't know how to see what happens when the connection drops out, or whether the connection closes. using mozilla dev tools console i don't see anything happening after the first POST request begins. the only thing that happens that i can see is that the little animated icon in my browser's tab disappears.

in the repo, in /resources/testfiles, test.pdf works, the humboldt file doesn't.

also, am i adjusting the correct settings? and should longer timeouts be possible? the file that doesn't work only takes just over 1 min to OCR, so the drop out is shorter than that.

i also tried making a binary and running that, and had the same effect. i also don't know if its my browser causing trouble.

weavejester commented 1 year ago

You mentioned that it worked with curl, but not in your browser. This may be because your browser response timeout is set low: check network.http.response.timeout in about:config. You might also want to try a different browser.

I'm afraid I can't reproduce your issue, perhaps because the humboldt test file completes in ~40s for me.

mooseyboots commented 1 year ago

so it works in links, chromium, and netsurf, but not in firefox, even with that setting changed and even in a blank profile with that setting changed.

obvs not a ring issue tho.

thanks for taking a look!