Skip to content

Response headers disappearing. #2456

@dvasquezlopez

Description

@dvasquezlopez

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!!)

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