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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to