openresty / openresty/lua-nginx-module
Attempting to send a custom chunked response after skipping access phase results in only partial response&hanging connection
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
Hi there, I'm using Openresty 1.15.8.3 with nginx 1.16.
I've been trying to return a custom chunked response, after skipping the access phase/upstream request. This is a trimmed down version of how I've tried to achieve this:
access_by_lua_block {
return ngx.exit(ngx.HTTP_OK) -- should skip upstream request
}
header_filter_by_lua_block {
ngx.header["content-length"] = nil -- should enable response streaming
}
body_filter_by_lua_block {
ngx.arg[1] = fetch_some_data() -- fetches the next chunk of data to return to the client
ngx.arg[2] = ngx.arg[1] == nil -- set EOF if no more data
}
Here, I'd expect body_filter_by_lua_block to be repeatedly called until EOF was set. Instead, what actually happens is body_filter_by_lua_block is only called once, then the next phase is called. The connection to the client (curl in this case) is left open, and is not closed.
Interestingly, if I allow the upstream request to go ahead by removing the access_by_lua_block block, then body_filter_by_lua_block is actually called repeatedly as expected. But I'd like to entirely avoid an upstream connection, so it's a no-go.
Is this a bug, or if not are there any workarounds?
Thanks!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided minimal configuration using access_by_lua_block, header_filter_by_lua_block, and body_filter_by_lua_block, then compare it with the version that permits the upstream request. Trace why the body filter runs only once after ngx.exit(ngx.HTTP_OK). Done means the custom chunks continue until EOF and the client connection closes without an upstream request.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, nginx
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100