apisix-java-plugin-runner icon indicating copy to clipboard operation
apisix-java-plugin-runner copied to clipboard

bug:在PluginFilter类中通过requiredRespBody()方法设置为true后,在插件中调用PostRequest.getUpstreamStatusCode()方法会偶现(概率很高)获取到不正确的响应码

Open beginnerWJC opened this issue 2 years ago • 4 comments

Issue description

在PluginFilter类中通过requiredRespBody()方法设置为true后,在插件中调用PostRequest.getUpstreamStatusCode()方法会偶现(概率很高)获取到不正确的响应码

Environment

  • apisix-java-plugin-runner 0.4.0
  • apisix 3.2.0
  • apisix-dashboard 3.0.0

Minimal test code / Steps to reproduce the issue

1.通过apisix-dashboard创建路由使用ext-plugin-post-resp插件 image 2.写一个简单的java测试插件,并且设置requiredRespBody()和requiredBody()都为true image 3.查看日志发现一会是正常的406,一会是57 image

What's the actual result? (including assertion message & call stack if applicable)

What's the expected result?

beginnerWJC avatar Apr 13 '23 05:04 beginnerWJC

这个和下面这个问题应该是一类问题 https://github.com/apache/apisix-java-plugin-runner/issues/234

beginnerWJC avatar Apr 13 '23 05:04 beginnerWJC

修正一下PostRequest的构造函数就行可以了: public PostRequest(Req req) { this.req = req; this.status = req.status(); headers = new HashMap<>(); for (int i = 0; i < req.headersLength(); i++) { TextEntry header = req.headers(i); headers.put(header.name(), header.value()); } }

frankqoqo8 avatar Sep 12 '23 09:09 frankqoqo8

@frankqoqo8 好的,感谢,我找时间验证一下

beginnerWJC avatar Sep 25 '23 13:09 beginnerWJC

It worked ! a non-official workaround https://github.com/gaoxingliang/apisix-java-plugin-runner/commit/6d1ccd30ab44f6faf5825d7891433be9f97b2ee7

gaoxingliang avatar Nov 22 '23 07:11 gaoxingliang