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/02/26 06:42:58 UTC

[GitHub] [apisix] Firstsawyou commented on a change in pull request #3682: chore: add safe limit to avoid infinite loop caused by bug

Firstsawyou commented on a change in pull request #3682:
URL: https://github.com/apache/apisix/pull/3682#discussion_r583416007



##########
File path: apisix/balancer/roundrobin.lua
##########
@@ -18,12 +18,19 @@
 local roundrobin  = require("resty.roundrobin")
 local core = require("apisix.core")
 local nkeys = core.table.nkeys
+local pairs = pairs
 
 
 local _M = {}
 
 
 function _M.new(up_nodes, upstream)
+    local safe_limit = 0
+    for _, weight in pairs(up_nodes) do
+        -- the weight can be zero
+        safe_limit = safe_limit + weight + 1

Review comment:
       I don't understand, why is `weight` needed here?
   Is it better than `safe_limit = safe_limit + 1` ?




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

For queries about this service, please contact Infrastructure at:
users@infra.apache.org