openresty / openresty/lua-nginx-module

inconsistency of ngx.ctx between access_by_lua and header_filter_by_lua when limit_req is set

Open
#1,848 1 comment 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

With this configuration

events {
    worker_connections 1024;
}


http {
    limit_req_zone $binary_remote_addr zone=req:100m rate=5r/s;
    limit_req zone=req burst=25;
	server{
		listen 80;
		location /{
			access_by_lua_block{
				ngx.log(ngx.ERR, 'access ', tostring(ngx.ctx))
			}
			proxy_pass http://www.baidu.com;
			header_filter_by_lua_block{
				ngx.log(ngx.ERR, 'content ', tostring(ngx.ctx))
			}
		}
	}
}

When test with ab or any other tools we can observe from log that some access_by_lua_block do not have a corressponding call to header_filter_by_lua_block with the same table address, and vice versa.

example for test: ab -c 100 -n 500 http://address/

The log is too long to paste here, which will be uploaded later.

It seems like responses are not associated to the request it's for. The problem goes away when set limit_req with nodelay setting.

below is env to reproduce the problem, which I don't think related:
OpenResty version: 1.17.8.2(binary release)
OS: Win 10

The problem also shows up for linux and my build with extra configuration. This enviroment is built to confirm it's not caused by build configuration.

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 issue with the provided nginx configuration and the ab -c 100 -n 500 command, comparing ngx.ctx addresses in the access and header-filter logs with and without nodelay. Start by tracing the limit_req request lifecycle and the Lua access/header-filter phases; done means determining whether the mismatch is reproducible and identifying the affected request association.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, lua, nginx
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.