Revolyssup commented on issue #12127:
URL: https://github.com/apache/apisix/issues/12127#issuecomment-2788714436

   Yeah this can be done. We can add an optional field `allowed_failure` on 
upstream. Like when set to 5xx, retries will be reset to a higher number and 
retry wont happen. Though for complex use cases, it would be recommended to do 
it in a custom plugin. See if something like the one below does your job
   ```lua
   local core = require("apisix.core")
   
   local plugin_name = "retry-control"
   
   local schema = {
       type = "object",
       properties = {
           non_retry_statuses = {
               type = "array",
               items = { type = "integer" },
               default = { 404, 412 } -- Example: Don't retry on these statuses
           }
       }
   }
   
   local _M = {
       version = 1.0,
       priority = 999, -- Set appropriate priority
       name = plugin_name,
       schema = schema,
   }
   
   function _M.check_schema(conf)
       return core.schema.check(schema, conf)
   end
   
   function _M.before_proxy(conf, ctx)
       -- Only execute during retries
       if not ctx.picked_server then
           local state, code = get_last_failure()
   
           -- Check if status code is in non-retry list
           if code and core.table.has_value(conf.non_retry_statuses, code) then
               core.log.warn("Aborting retry due to status code: ", code)
               ctx.proxy_retry_deadline = ngx_now() -- Force retry timeout
           end
       end
   
       return true
   end
   
   return _M
   ```


-- 
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