{"action":"opened","issue":{"url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/603","labels_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/603/labels{/name}","comments_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/603/comments","events_url":"https://api.github.com/repos/openresty/lua-nginx-module/issues/603/events","html_url":"https://github.com/openresty/lua-nginx-module/issues/603","id":117192161,"number":603,"title":"ngx.location.capture and sendfile","user":{"login":"cmaion","id":187317,"avatar_url":"https://avatars.githubusercontent.com/u/187317?v=3","gravatar_id":"","url":"https://api.github.com/users/cmaion","html_url":"https://github.com/cmaion","followers_url":"https://api.github.com/users/cmaion/followers","following_url":"https://api.github.com/users/cmaion/following{/other_user}","gists_url":"https://api.github.com/users/cmaion/gists{/gist_id}","starred_url":"https://api.github.com/users/cmaion/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cmaion/subscriptions","organizations_url":"https://api.github.com/users/cmaion/orgs","repos_url":"https://api.github.com/users/cmaion/repos","events_url":"https://api.github.com/users/cmaion/events{/privacy}","received_events_url":"https://api.github.com/users/cmaion/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-11-16T18:47:31Z","updated_at":"2015-11-16T18:47:31Z","closed_at":null,"body":"Hi,\r\n\r\nGot bitten by workers crashes in LUA due to ngx.location.capture requesting a location that has the ability to sendfile large files.\r\n\r\nFound out that if subrequests makes use of the X-Accel-Redirect, the actual file content gets fully loaded within the subrequest, and then sent back to LUA at once, as a single large chunk of memory... and potentially blowing stuff in the LUA VM.\r\n\r\nThis is actually understandable, but a quick note in the doc might help as it's easy to overlook this!\r\n\r\nMy fix in my case is to:\r\n1. push a different sendfile header from the backend (ie, something different than X-Accel-Redirect) in order to prevent the ngx.location.capture subrequest from loading the file,\r\n2. test this header when returning from ngx.location.capture() and,\r\n3. if found, use return ngx.exec(<header value>) to exit from LUA and stream the actual file to the client\r\n\r\nNot sure if a better/nicer way exists though!\r\n\r\nCedric"}}