@@ -65,6 +65,10 @@ local function check_conf(id, conf, need_id, schema, opts)
6565
6666 if conf .protocol and conf .protocol .superior_id and not opts .skip_references_check then
6767 local superior_id = conf .protocol .superior_id
68+ if id and tostring (superior_id ) == tostring (id ) then
69+ return nil , {error_msg = " stream route can not set itself as superior_id" }
70+ end
71+
6872 local key = " /stream_routes/" .. superior_id
6973 local res , err = core .etcd .get (key )
7074 if not res then
@@ -79,7 +83,12 @@ local function check_conf(id, conf, need_id, schema, opts)
7983
8084 local superior_route = res .body .node .value
8185 if type (superior_route ) == " string" then
82- superior_route = core .json .decode (superior_route )
86+ local decoded , decode_err = core .json .decode (superior_route )
87+ if not decoded then
88+ return nil , {error_msg = " failed to decode stream routes[" .. superior_id
89+ .. " ]: " .. decode_err }
90+ end
91+ superior_route = decoded
8392 end
8493
8594 if superior_route and superior_route .protocol
@@ -103,11 +112,11 @@ local function delete_checker(id)
103112 local key = " /stream_routes"
104113 local res , err = core .etcd .get (key , {prefix = true })
105114 if not res then
106- return nil , {error_msg = " failed to fetch stream routes: " .. err }
115+ return 503 , {error_msg = " failed to fetch stream routes: " .. err }
107116 end
108117
109118 if res .status ~= 200 then
110- return nil , {error_msg = " failed to fetch stream routes, response code: " .. res .status }
119+ return 503 , {error_msg = " failed to fetch stream routes, response code: " .. res .status }
111120 end
112121
113122 local nodes = res .body .list
@@ -124,7 +133,12 @@ local function delete_checker(id)
124133 for _ , item in ipairs (nodes ) do
125134 local route = item .value
126135 if type (route ) == " string" then
127- route = core .json .decode (route )
136+ local decoded , decode_err = core .json .decode (route )
137+ if not decoded then
138+ return 503 , {error_msg = " failed to decode stream route [" .. tostring (item .key )
139+ .. " ]: " .. decode_err }
140+ end
141+ route = decoded
128142 end
129143
130144 if route and route .protocol and tostring (route .protocol .superior_id ) == id then
0 commit comments