openresty / openresty/lua-nginx-module

Lua code in header_filter phase still runs after ngx.exit(401) is executed in access phase

Open
#2,279 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
11.8k
Forks
2.1k
Avg merge
6h 1m
Merged PRs (30d)
6

Description

I saw in the documentation that using ngx.exit(<200) would make the request return directly to the client without executing the lua code at various stages later, and my colleague told me that was correct, my colleague had previously used an older version of openrest (seems to be 1.19.X)
But I tested linux version 1.21.4.3 and windows version 1.25.3.1 and found that even if I executed ngx.exit(401) during the access phase, it still triggered lua script during the header_filter phase. Why? Did I use it wrong?

my nginx config

events {
    accept_mutex   off;
    worker_connections   20480;
}
http {
	server {
        error_log logs/error.log error;
		listen 80; 
		location / {
			proxy_set_header Host $host;
			access_by_lua_file test/access.lua;
			header_filter_by_lua_file test/header.lua;
		}
	}
} 

test/access.lua

ngx.log(ngx.ERR, "access.lua")
return ngx.exit(401) 

test/header.lua

ngx.log(ngx.ERR, "header.lua")

result (logs/error.log)

2024/01/22 15:47:31 [error] 157014#0: *1 [lua] access.lua:1: access.lua, client: 172.28.64.1, server: , request: "GET / HTTP/1.1", host: "172.28.73.58:80"
2024/01/22 15:47:31 [error] 157014#0: *1 [lua] header.lua:1: header.lua, client: 172.28.64.1, server: , request: "GET / HTTP/1.1", host: "172.28.73.58:80"

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the provided nginx configuration, test/access.lua, and test/header.lua, then compare the observed error.log entries with the documented ngx.exit behavior. Trace the access and header_filter entry points to determine whether this phase interaction is expected; done means the behavior and documentation are reconciled.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, nginx
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.