openresty / openresty/lua-nginx-module
Response headers disappearing.
Nobody has claimed this yet.
- Dominant language
- C
- Stars
- 11.8k
- Forks
- 2.1k
- Avg merge
- 6h 1m
- Merged PRs (30d)
- 6
Description
Hello,
I have a very strange issue where I'm setting a custom header and writing a simple message, and sometimes, the custom header is not part of the response. What is part of the response is a smaller set of headers that include server, chunked encoding, date. The body is not lost though.
First, I tried something in the access phase:
ngx.header["x-foo"] = "bar"
ngx.print("123")
Later on I used content phase:
ngx.header["x-foo"] = "bar"
ngx.print("123")
then I tried:
- content phase:
ngx.print("123") - header filter:
ngx.header["x-foo"] = "bar"
I had a couple asserts at the beginning of the lua block. I can assert that the request is not a subrequest.
I had an assert in header filter check "x-foo" was not set, and it fired intermediately. Like the header filter was executed multiple times but not all the times is executed twice. It seemed like the ngx.header was left behind for some reason.
I also tried in the content phase something like this:
ngx.header["x-foo"] = "bar"
ngx.send_headers()
headers, err = ngx.resp.get_headers()
and then assert that the headers in the response included "x-foo". It failed intermediately. Please note I did check the headers were not truncated (they shouldn't' I didn't se anything else).
The failure happened not during high concurrency, I have around 30 tests written in rust doing the http 1.1 requests. The tests run in parallel. But there is nothing interesting there, except they always inspect "x-foo".
Other things that I tried were setting the content-length, it was also dropped when the error occurred.
When the error occurred, the content-type was read from my nginx http block (it used whatever I set in default_type).
Also, when I detected after the forced "send_headers()" call that the response didn't agree with the headers I set, I closed the connection with ngx.exit(ngx.ERROR) and the client retried, however, it was not able to succeed on retry, like the state didn't clean up properly. Please note that ngx.exit(ngx.ERROR) was just to try to mitigate the issue, but the issue happened without any ngx.exit() call.
I have the ngx/lua-ngx-module setup ready so I can do tracing, code changes, compile and run. But I (and many LLMs) run out of ideas where to investigate.
My ask here is to do a sanity check as this is an intermediate failure. Suggestions to look at?
(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
No source file or test is named. Begin by reproducing the intermittent loss through the content phase, header filter, ngx.header, and ngx.send_headers paths, using the parallel Rust HTTP/1.1 tests and tracing. Done means identifying why response state is not preserved and documenting a reproducible fix or a narrowed cause.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, lua, nginx
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100