Skip to content

Commit

Permalink
fix: distinguish different routes which has the same service (#2840)
Browse files Browse the repository at this point in the history
Fix #2828.

The bug is introduced in #2121.

Can't be reproduced in over 1 millions requests after applying this
patch.
  • Loading branch information
spacewander authored Nov 25, 2020
1 parent 1ad90f7 commit 67eb787
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
3 changes: 2 additions & 1 deletion apisix/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@ function _M.merge_service_route(service_conf, route_conf)
core.log.info("service conf: ", core.json.delay_encode(service_conf))
core.log.info(" route conf: ", core.json.delay_encode(route_conf))

local route_service_key = route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex
local route_service_key = route_conf.value.id .. "#"
.. route_conf.modifiedIndex .. "#" .. service_conf.modifiedIndex
return merged_route(route_service_key, service_conf,
merge_service_route,
service_conf, route_conf)
Expand Down
41 changes: 41 additions & 0 deletions t/config-center-yaml/route-service.t
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ routes:
-
uri: /hello
service_id: 1
id: 1
services:
-
id: 1
Expand All @@ -62,6 +63,7 @@ hello world
routes:
-
uri: /hello
id: 1
service_id: 1111
services:
-
Expand All @@ -84,6 +86,7 @@ failed to fetch service configuration by id: 1111
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
services:
Expand Down Expand Up @@ -115,6 +118,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
Expand Down Expand Up @@ -149,6 +153,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
Expand Down Expand Up @@ -184,6 +189,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
Expand Down Expand Up @@ -211,3 +217,38 @@ GET /hello
hello world
--- no_error_log
[error]
=== TEST 7: two routes with the same service
--- yaml_config eval: $::yaml_config
--- apisix_yaml
routes:
- uris:
- /hello
service_id: 1
id: 1
plugins:
response-rewrite:
body: "hello\n"
- uris:
- /world
service_id: 1
id: 2
plugins:
response-rewrite:
body: "world\n"
services:
-
id: 1
upstream:
nodes:
"127.0.0.1:1980": 1
type: roundrobin
#END
--- request
GET /hello
--- response_body
hello
--- no_error_log
[error]
5 changes: 5 additions & 0 deletions t/config-center-yaml/route-upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstreams:
Expand All @@ -60,6 +61,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1111
upstreams:
Expand All @@ -82,6 +84,7 @@ failed to find upstream by id: 1111
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstream:
Expand Down Expand Up @@ -109,6 +112,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstreams:
Expand Down Expand Up @@ -139,6 +143,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /get
upstream_id: 1
upstreams:
Expand Down
3 changes: 3 additions & 0 deletions t/config-center-yaml/route.t
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream:
nodes:
Expand Down Expand Up @@ -82,6 +83,7 @@ use config_center: yaml
--- apisix_yaml
routes:
-
id: 1
uri: /hello
host: foo.com
upstream:
Expand All @@ -106,6 +108,7 @@ hello world
stream_routes:
- server_addr: 127.0.0.1
server_port: 1985
id: 1
upstream:
nodes:
"127.0.0.1:1995": 1
Expand Down

0 comments on commit 67eb787

Please sign in to comment.