You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2021/07/31 18:05:45 UTC
[GitHub] [apisix-java-plugin-runner] tzssangglass opened a new issue #55: bug: using stop-request but not calling setStatusCode will trigger an exception
tzssangglass opened a new issue #55:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/55
### Issue description
If using `stop-request` but not calling `setStatusCode` will trigger an exception will trigger an internal exception in APISIX.
### Environment
* your apisix-java-plugin-runner version: master
* apisix version: master
### Minimal test code / Steps to reproduce the issue
1. java code
```java
package org.apache.apisix.plugin.runner.filter;
import org.apache.apisix.plugin.runner.HttpRequest;
import org.apache.apisix.plugin.runner.HttpResponse;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;
@Component
public class TestFilter implements PluginFilter {
@Override
public String name() {
return "TestFilter";
}
@Override
public Mono<Void> filter(HttpRequest request, HttpResponse response, PluginFilterChain chain) {
response.setHeader("para_test", "test");
return chain.filter(request, response);
}
}
```
2. apisix route
```shell
$ curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"uri":"/*",
"plugins":{
"ext-plugin-pre-req":{
"conf":[
{
"name":"TestFilter",
"value":"bar"
}
]
}
},
"upstream":{
"nodes":{
"httpbin.org:80":1
},
"type":"roundrobin"
}
}'
```
3. access apisix
```shell
$ curl -i 127.0.0.1:9080/get
```
4. the `error.log` of apisix
```
2021/08/01 01:40:03 [error] 124925#124925: *152 failed to run balancer_by_lua*: /usr/local/apisix/apisix/balancer.lua:181: attempt to index local 'up_conf' (a nil value)
stack traceback:
/usr/local/apisix/apisix/balancer.lua:181: in function 'pick_server'
/usr/local/apisix/apisix/balancer.lua:268: in function 'run'
/usr/local/apisix/apisix/init.lua:710: in function 'http_balancer_phase'
balancer_by_lua:2: in main chunk while connecting to upstream, client: 127.0.0.1, server: _, request: "GET /get HTTP/1.1", host: "127.0.0.1:9080"
```
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-java-plugin-runner] spacewander closed issue #55: bug: using stop-request but not calling setStatusCode will trigger an exception
Posted by GitBox <gi...@apache.org>.
spacewander closed issue #55:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/55
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #55: bug: using stop-request but not calling setStatusCode will trigger an exception
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #55:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/55#issuecomment-890389263
And APISIX and Java-Plugin-Runner e2e tests also need to be scheduled in advance……
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #55: bug: using stop-request but not calling setStatusCode will trigger an exception
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #55:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/55#issuecomment-890388783
here are the reasons for the bug:
1. If the java-runner stop request does not set a response status code, then the APISIX side replaces it with a 0 when decoding,
[where to call](https://github.com/apache/apisix/blob/b967b8accabc06d3ffbda61630bce3faddb0cb10/apisix/plugins/ext-plugin/init.lua#L434)
```lua
true, nil, stop:Status(), body
```
and the [`stop:Status()`](https://github.com/api7/ext-plugin-proto/blob/9a1acd4e459011a0278cfe7a18490c36e6b2eb03/lua/A6/HTTPReqCall/Stop.lua#L27-L33)
```lua
function Stop_mt:Status()
local o = self.view:Offset(4)
if o ~= 0 then
return self.view:Get(flatbuffers.N.Uint16, o + self.view.pos)
end
return 0
end
```
2. `code = 0` will be passed to the [`resp_exit`](https://github.com/apache/apisix/blob/b967b8accabc06d3ffbda61630bce3faddb0cb10/apisix/core/response.lua#L80-L82) function of response process
```lua
if code then
return ngx_exit(code)
end
```
3. [**ngx_exit(0) ** causes abnormal behavior in APISIX]
according to [ngx.exit](https://github.com/openresty/lua-nginx-module#ngxexit): When `status` == 0 (i.e., ngx.OK), it will only quit the current phase handler (or the content handler if the content_by_lua* directive is used) and continue to run later phases (if any) for the current request.
This explains why this request goes to the `balancer` phase.
I think we should do compile-time detection in java-runner: if developer use the `stop-request`, then they must call `setStatusCode`. And we could use 500 as the default code (for other exceptions).
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix-java-plugin-runner] tzssangglass commented on issue #55: bug: using stop-request but not calling setStatusCode will trigger an exception
Posted by GitBox <gi...@apache.org>.
tzssangglass commented on issue #55:
URL: https://github.com/apache/apisix-java-plugin-runner/issues/55#issuecomment-890389312
I will fix this bug soon.
--
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: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org