{"action":"created","issue":{"url":"https://api.github.com/repos/ztellman/aleph/issues/169","labels_url":"https://api.github.com/repos/ztellman/aleph/issues/169/labels{/name}","comments_url":"https://api.github.com/repos/ztellman/aleph/issues/169/comments","events_url":"https://api.github.com/repos/ztellman/aleph/issues/169/events","html_url":"https://github.com/ztellman/aleph/issues/169","id":93218918,"number":169,"title":"Question: Large responses when Aleph behind nginx?","user":{"login":"zentrope","id":95732,"avatar_url":"https://avatars.githubusercontent.com/u/95732?v=3","gravatar_id":"","url":"https://api.github.com/users/zentrope","html_url":"https://github.com/zentrope","followers_url":"https://api.github.com/users/zentrope/followers","following_url":"https://api.github.com/users/zentrope/following{/other_user}","gists_url":"https://api.github.com/users/zentrope/gists{/gist_id}","starred_url":"https://api.github.com/users/zentrope/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zentrope/subscriptions","organizations_url":"https://api.github.com/users/zentrope/orgs","repos_url":"https://api.github.com/users/zentrope/repos","events_url":"https://api.github.com/users/zentrope/events{/privacy}","received_events_url":"https://api.github.com/users/zentrope/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2015-07-06T08:08:48Z","updated_at":"2015-07-07T05:53:14Z","closed_at":null,"body":"I've got an app serving up a large clojurescript file. Works great when I run the app standalone or from an uberjar.\r\n\r\nWhen I put the standalone app behind an nginx proxy, I have trouble downloading the \"main.js\" file via proxy_pass.\r\n\r\n    49902#0: *461 upstream prematurely closed connection while reading upstream, client\r\n\r\nUnder advanced optimization, the file is still 300K. I'm not interested in a fast download (yet), just a consistent one.\r\n\r\nThe operative code is here: [github](https://github.com/zentrope/cipher/blob/master/src/clj/cipher/main.clj#L169-L183) It reads resource files from the file system into a response.\r\n\r\nI tried using a `deferred` for the whole response (actually reading the files in a thread), or returning a `stream` as the body. Not much better.\r\n\r\nWhat I have _not_ tried is chucking the read from the file(s) and putting them to the stream in fixed sized chunks.\r\n\r\nIs that that preferred strategy for large (3MB or 300K) files served out via Aleph?\r\n\r\nIs there maybe something problematic with nginx 1.8.0?\r\n\r\nFinally, there are options to adjust ServerBootstrap (and a few other objects), though I found the javadoc for those, uh, not immediately obvious. Is that where to look?\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ztellman/aleph/issues/comments/119081022","html_url":"https://github.com/ztellman/aleph/issues/169#issuecomment-119081022","issue_url":"https://api.github.com/repos/ztellman/aleph/issues/169","id":119081022,"user":{"login":"ztellman","id":31295,"avatar_url":"https://avatars.githubusercontent.com/u/31295?v=3","gravatar_id":"","url":"https://api.github.com/users/ztellman","html_url":"https://github.com/ztellman","followers_url":"https://api.github.com/users/ztellman/followers","following_url":"https://api.github.com/users/ztellman/following{/other_user}","gists_url":"https://api.github.com/users/ztellman/gists{/gist_id}","starred_url":"https://api.github.com/users/ztellman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ztellman/subscriptions","organizations_url":"https://api.github.com/users/ztellman/orgs","repos_url":"https://api.github.com/users/ztellman/repos","events_url":"https://api.github.com/users/ztellman/events{/privacy}","received_events_url":"https://api.github.com/users/ztellman/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T05:53:14Z","updated_at":"2015-07-07T05:53:14Z","body":"Hmm, that's a very odd set of workarounds. To clarify, those curls are to\nNginx, or straight to the server?\n\nOn Mon, Jul 6, 2015, 11:55 PM Keith Irwin <notifications@github.com> wrote:\n\n> Okay, some interesting new data points:\n>\n> Using:\n>\n> [aleph \"0.4.1-alpha1\"]\n>\n> If I chunk the response (to-byte-buffers {:chunck-size 2048}) , things\n> seem a little better, but there are still premature closes unless I\n> explicitly delay the closing of the stream.\n>\n> Here's the code:\n>\n> (good-response [rsrc path]\n>  (let [stream (stream/stream)]\n>    (async/thread\n>      (doseq [b (bs/to-byte-buffers rsrc {:chunk-size 2048})]\n>        (stream/put! stream b))\n>      (Thread/sleep 100)\n>      (stream/close! stream))\n>    {:status 200\n>     :body stream\n>     :headers {\"content-type\" (mime-for path)}}))\n>\n> Notice the (Thread/sleep 100). Doing that results in there *never* being\n> a premature close in a browser, even when I right cmd-R without letting\n> up.\n>\n> However, curl with -v, printing out the data on the console each time,\n> will sometimes result in the premature close.\n>\n>  curl -v http://doom.local/main.js\n>\n> but doing this:\n>\n>  curl -v http://doom.local/main.js > /dev/null\n>\n> never results in the problem (at least as fast as I can up-arrow-return\n> it).\n>\n> —\n> Reply to this email directly or view it on GitHub\n> <https://github.com/ztellman/aleph/issues/169#issuecomment-119008075>.\n>\n"}}