beginnerWJC opened a new issue, #7792:
URL: https://github.com/apache/apisix/issues/7792
### Current Behavior
When using the APISIX ext-plugin-post-resp plugin and apisix java plugin
runner 0.3.0 to rewrite the upstream response header, when the upstream return
status code is 204, this HTTP request apisix will be sent twice
### Expected Behavior
_No response_
### Error Logs
upstream return status code is 204
the logs of APISIX(Sent twice)
```
2022/08/25 05:01:15 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:01:15.190 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -TestPostFilter插件开始执行!
, context: ngx.timer
2022/08/25 05:01:15 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:01:15.191 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的headers:{"Date":"Thu, 25 Aug 2022
05:01:15 GMT"}
, context: ngx.timer
2022/08/25 05:01:15 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:01:15.191 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的状态码为:204
, context: ngx.timer
2022/08/25 05:01:15 [warn] 48#48: *849033 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus while sending to
client, client: 172.17.67.0, server: _, request: "GET
/robot-monitor/v1/robotMonitor/test204 HTTP/1.1", upstream:
"http://192.168.2.120:8900/robot-monitor/v1/robotMonitor/test204", host:
"192.168.40.174:30880"
2022/08/25 05:01:15 [warn] 48#48: *849033 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus while sending to
client, client: 172.17.67.0, server: _, request: "GET
/robot-monitor/v1/robotMonitor/test204 HTTP/1.1", upstream:
"http://192.168.2.120:8900/robot-monitor/v1/robotMonitor/test204", host:
"192.168.40.174:30880"
2022/08/25 05:01:15 [warn] 48#48: *849033 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus while logging
request, client: 172.17.67.0, server: _, request: "GET
/robot-monitor/v1/robotMonitor/test204 HTTP/1.1", upstream:
"http://192.168.2.120:8900/robot-monitor/v1/robotMonitor/test204", host:
"192.168.40.174:30880"
172.17.67.0 - - [25/Aug/2022:05:01:15 +0000] 192.168.40.174:30880 "GET
/robot-monitor/v1/robotMonitor/test204 HTTP/1.1" 204 0 0.010 "-"
"PostmanRuntime/7.28.4" 192.168.2.120:8900 204 0.004
"http://192.168.40.174:30880"
```
the logs of java plugin runner
```
08/25 05:01:15.190 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -TestPostFilter插件开始执行!
08/25 05:01:15.191 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的headers:{"Date":"Thu, 25 Aug 2022
05:01:15 GMT"}
08/25 05:01:15.191 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的状态码为:204
```
the logs of upstream(Got it twice)
```
2022-08-25 13:01:15.175 INFO 28652 --- [ XNIO-1 task-3]
c.w.controller.RobotMonitorController : test204
2022-08-25 13:01:15.175 INFO 28652 --- [ XNIO-1 task-3]
com.wellcloud.common.aspect.LogAspect : request: test204, cost: 0
2022-08-25 13:01:15.180 INFO 28652 --- [ XNIO-1 task-4]
c.w.controller.RobotMonitorController : test204
2022-08-25 13:01:15.181 INFO 28652 --- [ XNIO-1 task-4]
com.wellcloud.common.aspect.LogAspect : request: test204, cost: 1
```
When using the APISIX ext-plugin-post-resp plugin and apisix java plugin
runner 0.3.0 to rewrite the upstream response header, when the upstream return
status code is 204, this HTTP request apisix will be sent twice
if upstream return status code is 200. it is normal
the logs of APISIX
```
2022/08/25 05:13:26 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:13:26.124 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -TestPostFilter插件开始执行!
, context: ngx.timer
2022/08/25 05:13:26 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:13:26.125 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter]
-上游返回的headers:{"Connection":"keep-alive","Content-Length":"0","Date":"Thu, 25
Aug 2022 05:13:26 GMT"}
, context: ngx.timer
2022/08/25 05:13:26 [warn] 57#57: *191 [lua] init.lua:913: 08/25
05:13:26.125 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的状态码为:200
, context: ngx.timer
2022/08/25 05:13:26 [warn] 50#50: *936815 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus, client:
172.17.67.0, server: _, request: "GET /robot-monitor/v1/robotMonitor/test200
HTTP/1.1", host: "192.168.40.174:30880"
2022/08/25 05:13:26 [warn] 50#50: *936815 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus, client:
172.17.67.0, server: _, request: "GET /robot-monitor/v1/robotMonitor/test200
HTTP/1.1", host: "192.168.40.174:30880"
2022/08/25 05:13:26 [warn] 50#50: *936815 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus, client:
172.17.67.0, server: _, request: "GET /robot-monitor/v1/robotMonitor/test200
HTTP/1.1", host: "192.168.40.174:30880"
2022/08/25 05:13:26 [warn] 50#50: *936815 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus, client:
172.17.67.0, server: _, request: "GET /robot-monitor/v1/robotMonitor/test200
HTTP/1.1", host: "192.168.40.174:30880"
2022/08/25 05:13:26 [warn] 50#50: *936815 [lua] plugin.lua:384:
trace_plugins_info_for_debug(): Apisix-Plugins: prometheus while logging
request, client: 172.17.67.0, server: _, request: "GET
/robot-monitor/v1/robotMonitor/test200 HTTP/1.1", host: "192.168.40.174:30880"
172.17.67.0 - - [25/Aug/2022:05:13:26 +0000] 192.168.40.174:30880 "GET
/robot-monitor/v1/robotMonitor/test200 HTTP/1.1" 200 5 0.033 "-"
"PostmanRuntime/7.28.4" - - - "http://192.168.40.174:30880"
```
the logs of java plugin runner
```
08/25 05:13:26.124 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -TestPostFilter插件开始执行!
08/25 05:13:26.125 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter]
-上游返回的headers:{"Connection":"keep-alive","Content-Length":"0","Date":"Thu, 25
Aug 2022 05:13:26 GMT"}
08/25 05:13:26.125 [epollEventLoopGroup-2-1] INFO
[o.a.a.p.runner.filter.TestPostFilter] -上游返回的状态码为:200
```
the logs of upstream
```
2022-08-25 13:13:26.096 INFO 28652 --- [ XNIO-1 task-5]
c.w.controller.RobotMonitorController : test200
2022-08-25 13:13:26.096 INFO 28652 --- [ XNIO-1 task-5]
com.wellcloud.common.aspect.LogAspect : request: test200, cost: 0
```
### Steps to Reproduce
1.Run APISX via the Docker image
2.Run apisix-dashboard via the Docker image
3.write java plugin
```
public void postFilter(PostRequest request, PostResponse response,
PluginFilterChain chain) {
logger.info("TestPostFilter插件开始执行!");
Map<String, String> headersMap = request.getUpstreamHeaders();
logger.info("上游返回的headers:{}",JSON.toJSONString(headersMap));
int statusCode = request.getUpstreamStatusCode();
logger.info("上游返回的状态码为:{}",statusCode);
response.setHeader("apisix", "TestPostFilter");
chain.postFilter(request, response);
}
```
4.write test upstream interface
```
@ApiOperation(value="test204")
@RequestMapping(value="/test204",method=RequestMethod.GET)
@ResponseStatus(code = HttpStatus.NO_CONTENT)
public void test204()throws CustomException{
logger.info("test204");
}
@ApiOperation(value="test200")
@RequestMapping(value="/test200",method=RequestMethod.GET)
public void test200()throws CustomException{
logger.info("test200");
}
```
5.config route to proxy upstream
```
{
"uri": "/robot-monitor/v1/*",
"name": "test",
"methods": [
"GET",
"POST",
"PUT",
"DELETE"
],
"plugins": {
"ext-plugin-post-resp": {
"conf": [
{
"name": "TestPostFilter",
"value": "{}"
}
],
"disable": false
}
},
"upstream": {
"nodes": [
{
"host": "192.168.2.120",
"port": 8900,
"weight": 1
}
],
"timeout": {
"connect": 6,
"send": 6,
"read": 6
},
"type": "roundrobin",
"scheme": "http",
"pass_host": "pass",
"keepalive_pool": {
"idle_timeout": 60,
"requests": 1000,
"size": 320
}
},
"status": 1
}
```
6.test it and find upstream return status code is 200. It is normal. but
upstream return status code is 204. This HTTP request apisix will be sent twice
### Environment
- APISIX version (run `apisix version`): 2.15.0
- Operating system (run `uname -a`): No relation
- OpenResty / Nginx version (run `openresty -V` or `nginx -V`): No relation
- etcd version, if relevant (run `curl
http://127.0.0.1:9090/v1/server_info`): 3.4.0
- APISIX Dashboard version, if relevant: 2.13.0
- Plugin runner version, for issues related to plugin runners:
apisix-java-plugin-runner: 0.3.0
- LuaRocks version, for installation issues (run `luarocks --version`): No
relation
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]