jujiale commented on issue #9831:
URL: https://github.com/apache/apisix/issues/9831#issuecomment-1633983595

   what I concern is in the following code: traffic-split.lua
   
   code A:
   `
   
   
             local function new_rr_obj(weighted_upstreams)
             local server_list = {}
             for i, upstream_obj in ipairs(weighted_upstreams) do
                 if upstream_obj.upstream_id then
                     server_list[upstream_obj.upstream_id] = upstream_obj.weight
                 elseif upstream_obj.upstream then
                     -- Add a virtual id field to uniquely identify the 
upstream key.
                     upstream_obj.upstream.vid = i
                     -- Get the table id of the nodes as part of the 
upstream_key,
                     -- avoid upstream_key duplicate because vid is the same in 
the loop
                     -- when multiple rules with multiple weighted_upstreams 
under each rule.
                     -- see https://github.com/apache/apisix/issues/5276
                     local node_tid = 
tostring(upstream_obj.upstream.nodes):sub(#"table: " + 1)
                     upstream_obj.upstream.node_tid = node_tid
                     server_list[upstream_obj.upstream] = upstream_obj.weight
                 else
                     -- If the upstream object has only the weight value, it 
means
                     -- that the upstream weight value on the default route has 
been reached.
                     -- Mark empty upstream services in the plugin.
                     upstream_obj.upstream = "plugin#upstream#is#empty"
                     server_list[upstream_obj.upstream] = upstream_obj.weight
         
                 end
             end
         
             return roundrobin:new(server_list)
         end
   
   
   
   `
   
   
   it also have a lru cache
   codeB:
   `
   
        local rr_up, err = lrucache(weighted_upstreams, nil, new_rr_obj, 
weighted_upstreams)
   
   
   `
   
   when traffic-split config is the following:
   `
   
                 {
                  "traffic-split": {
                          "disable": false,
                          "rules": [{
                                  "weighted_upstreams": [{
                                          "weight": 0
                                  }, {
                                          "upstream_id": "466807194923303750",
                                          "weight": 100
                                  }, {
                                          "upstream_id": "466807194721978186",
                                          "weight": 0
                                  }]
                          }]
                  }
             }
   
   
   `
   
   if the request hit the following config:
   `
   
       
            {
                                          "weight": 0
                                  }
   
   `
   because upstream_obj.upstream is nil .so it enters:
   `
   
   
               upstream_obj.upstream = "plugin#upstream#is#empty"
               server_list[upstream_obj.upstream] = upstream_obj.weight
   
   `
   
   so this time. the upstream_obj has upstream_obj.upstream. it is 
"plugin#upstream#is#empty". and it's type is string.
   
   so next time. when another request comes. the lrucache also exists. so it 
hit :
   `
   
        elseif upstream_obj.upstream then
               -- Add a virtual id field to uniquely identify the upstream key.
               upstream_obj.upstream.vid = i
   
   
   `
   because the  upstream_obj.upstream is "plugin#upstream#is#empty". so error: 
/traffic-split.lua:209: attempt to index field 'upstream' (a string value)  
occurs.
   
   I don't know if it is true, so please evalute it. thanks a lot.
   
   
   


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