Skip to content

ngx.location.capture and sendfile #603

Closed
@cmaion

Description

@cmaion

Hi,

Got bitten by workers crashes in LUA due to ngx.location.capture requesting a location that has the ability to sendfile large files.

Found 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.

This is actually understandable, but a quick note in the doc might help as it's easy to overlook this!

My fix in my case is to:

  1. 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,
  2. test this header when returning from ngx.location.capture() and,
  3. if found, use return ngx.exec(header value) to exit from LUA and stream the file back to the client

Not sure if a better/nicer way exists though!

Cedric

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions