bug: Request the route of the same service for a short time, the path is lost
Issue description
When two routes of the same upstream-service are requested, the first route responds successfully, and the second route shows path loss, or the response value is the same as the first route. After a period of time, about 1-2 minutes, the access to the second one will respond normally, but the same problem occurs when accessing the first one. The current phenomenon has found that in the same upstream service, the routes of multiple upstream services are accessed in a short time. The problem did not occur.
yaml configuration example, confidential information has been hidden
routes:
- id: 30101
priority: 0
methods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
uris:
- /doc/auth/*
hosts:
- t.com
service_id: 20001
name: 获取文档
plugins:
proxy-rewrite:
uri: /v1/doc
scheme: http
- id: 30305
priority: 0
methods:
- GET
- OPTIONS
uris:
- /account/rsa
hosts:
- t.com
service_id: 20003
name: 获取RSA密钥
plugins:
proxy-rewrite:
uri: /v1/account/rsa
scheme: http
- id: 30301
priority: 0
methods:
- OPTIONS
- POST
uris:
- /account/captcha
hosts:
- t.com
service_id: 20003
name: 生成验证码
plugins:
proxy-rewrite:
uri: /v1/account/captcha
scheme: http
services:
# auth
- id: 20001
name: "auth-services"
desc: "auth service"
upstream_id: 10001
plugins:
cors:
allow_origins: "*"
expose_headers: "*"
max_age: 5
allow_headers: "*"
allow_methods: "*"
- id: 20003
name: "account-services"
desc: "account service"
upstream_id: 10002
plugins:
cors:
allow_origins: "*"
expose_headers: "*"
max_age: 5
allow_headers: "*"
allow_methods: "*"
upstreams:
- id: 10001
name: "auth-upstreams"
desc: "auth service"
enable_websocket: false
nodes:
"auth.default.svc.cluster.local:8080": 1
hash_on: vars
type: roundrobin
- id: 10002
name: "account-upstreams"
desc: "account service"
enable_websocket: false
nodes:
"account.default.svc.cluster.local:8080": 1
hash_on: vars
type: roundrobin
global_rules:
- plugins:
limit-count:
time_window: 60
key: http_x_real_ip
count: 1000
rejected_code: 503
policy: local
response-rewrite:
headers:
Server: T Gateway
request-id:
include_in_response: true
header_name: X-Request-Id
When I approached the 30301 and 30305 routes at the same time, 30301 would return normally and the forwarded path would be normal. 30305 is a little later, and sometimes it is incorrectly forwarded to the root path of the upstream service, that is, the path is lost. Sometimes it will be the same as the return value of 30301. While accessing 30301 and 30101 at the same time, this problem will not occur. This kind of problem will last about 1 minute after the first visit, I wonder if my description is clear
①
First visit
Close to the same time

②
First visit
Close to the same time

When this problem occurs, I access an interface of another service, and the service interface will return to normal, but the problem will occur again as described above
Environment
- apisix version (cmd:
apisix version): v2.0 yaml - OS:centos7
Minimal test code / Steps to reproduce the issue
1. 2. 3.
What's the actual result? (including assertion message & call stack if applicable)
What's the expected result?
In addition, in version 2.0, when the global plug-in settings return to the head, two servers will appear. One of the apisix, one is my custom. Is it to show that apisix provides services? Because in my previous versions, the client used the server in the returned header as the judgment condition. I don’t know if this phenomenon is a bug or intentional
response-rewrite:
headers:
Server: T Gateway
when i enable config 'enable_debug'
020/11/24 03:19:08 [error] 17#17: *6274 failed to run log_by_lua*: /usr/local/apisix/apisix/core/response.lua:128: headers have already been sent
stack traceback:
[C]: in function 'error'
/usr/local/apisix/apisix/core/response.lua:96: in function 'set_header'
/usr/local/apisix/apisix/core/response.lua:128: in function 'set_header'
/usr/local/apisix/apisix/plugin.lua:227: in function 'filter'
/usr/local/apisix/apisix/init.lua:597: in function 'common_phase'
/usr/local/apisix/apisix/init.lua:679: in function 'http_log_phase'
log_by_lua(nginx.conf:248):2: in main chunk while logging request, client: 127.0.0.1, server: , request: "POST /account/captcha HTTP/1.1", upstream: "http://172.20.255.25:8080/v1/account/captcha", host: "t.com"
2020/11/24 03:19:10 [error] 16#16: *6419 failed to run body_filter_by_lua*: /usr/local/apisix/apisix/core/response.lua:128: headers have already been sent
stack traceback:
[C]: in function 'error'
/usr/local/apisix/apisix/core/response.lua:96: in function 'set_header'
/usr/local/apisix/apisix/core/response.lua:128: in function 'set_header'
/usr/local/apisix/apisix/plugin.lua:227: in function 'filter'
/usr/local/apisix/apisix/init.lua:597: in function 'common_phase'
/usr/local/apisix/apisix/init.lua:619: in function 'http_body_filter_phase'
body_filter_by_lua:2: in main chunk while sending to client, client: 127.0.0.1, server: , request: "GET /account/rsa HTTP/1.1", upstream: "http://172.20.255.25:8080/v1/account/rsa", host: "t.com", referrer: "https://t.com/"
cc @idbeta
@backnero Does your yaml file end with #END ? This is a keyword.
ref to :https://github.com/apache/apisix/blob/master/doc/stand-alone.md
In addition, in version 2.0, when the global plug-in settings return to the head, two servers will appear. One of the apisix, one is my custom. Is it to show that apisix provides services?
Actually the upstream's Server was leaked by accident. And we have changed this behavior.
when i enable config 'enable_debug'
There is a pending PR to solve the problem: https://github.com/apache/apisix/pull/2029 @membphis
@backnero Sorry, I don’t understand your question very well, can you describe it in simple words?
I can't reproduce it at my side.
I used the given configuration with hosts changed and limit-count removed (so that we can hit it millions of times).
Here is my backend:
worker_processes 1;
daemon off;
error_log stderr error;
events {
worker_connections 65535;
}
http {
server {
listen 28000 reuseport;
location = /v1/account/rsa {
return 200 "rsa";
}
location = /v1/account/captcha {
return 200 "captcha";
}
location / {
access_by_lua_block {
ngx.exit(500)
}
}
}
}
The wrk script:
local paths = {
"/account/captcha",
"/account/rsa",
}
local counter = 1
local threads = {}
function setup(thread)
math.randomseed(counter)
counter = counter + 1
end
function request()
local path = paths[math.random(2)]
return wrk.format(nil, path)
end
Then run:
wrk -t 4 http://127.0.0.1:9080 -s rand.lua -d 600
Running 10m test @ http://127.0.0.1:9080
4 threads and 10 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 420.31us 424.80us 33.87ms 98.41%
Req/Sec 4.86k 556.32 7.02k 67.24%
11608467 requests in 10.00m, 4.03GB read
Requests/sec: 19347.24
Transfer/sec: 6.88MB
Still can't reproduce it in 10 millions requests.
@backnero Can you provide the packet capture file contains the bad response?
@membphis
@backnero您的
yaml文件结尾#END吗?这是一个关键字。引用到:https : //github.com/apache/apisix/blob/master/doc/stand-alone.md
There is #END, there is no error about apisix.yaml configuration in the error log
@backnero对不起,我不太清楚您的问题,可以用简单的词形容吗?
I configured the upstream, service, and routing information through yaml. When I access Route A and Route B of the same service at the same time, if Route A visits earlier, Route B returns the response of Route A.
When I visit the routes of other services at this time, I will get the correct response when visiting route B, but visiting route A will get the response information of route B In other words, requests forwarded by the gateway to the same service seem to be cached.
我无法在自己身边复制它。
我使用给定的配置来更改和
limit-count删除主机(这样我们就可以击中数百万次)。 这是我的后端:worker_processes 1; daemon off; error_log stderr error; events { worker_connections 65535; } http { server { listen 28000 reuseport; location = /v1/account/rsa { return 200 "rsa"; } location = /v1/account/captcha { return 200 "captcha"; } location / { access_by_lua_block { ngx.exit(500) } } } }wrk脚本:
local paths = { "/account/captcha", "/account/rsa", } local counter = 1 local threads = {} function setup(thread) math.randomseed(counter) counter = counter + 1 end function request() local path = paths[math.random(2)] return wrk.format(nil, path) end然后运行:
wrk -t 4 http://127.0.0.1:9080 -s rand.lua -d 600 Running 10m test @ http://127.0.0.1:9080 4 threads and 10 connections Thread Stats Avg Stdev Max +/- Stdev Latency 420.31us 424.80us 33.87ms 98.41% Req/Sec 4.86k 556.32 7.02k 67.24% 11608467 requests in 10.00m, 4.03GB read Requests/sec: 19347.24 Transfer/sec: 6.88MB仍然无法在1000万个请求中重现它。
@backnero 能否提供包含错误响应的数据包捕获文件?
If you use odd and even numbers for paths in the wrk script, polling has been reached. (I am not familiar with wrk, just a guess.) You can output the response message, if it appears rsa rsa rsa rsa ··· or it could be captcha captcha captcha captcha captcha ··· Is to reproduce my problem
This problem has never occurred before, I use apache/apisix:2.0-centos on dockerhub
Use yaml to configure upstream and other information
I tried to deploy in multiple environments online and offline, and it still exists.
Don't know the cause of the problem.
OK, now I can reproduce the issue, by applying the change in https://github.com/apache/apisix/pull/2838. I see something interesting in the access log:
"GET /account/captcha HTTP/1.1" ... "http://127.0.0.1/v1/account/rsa"