fix: distinguish different routes which has the same service (#2840)

Fix #2828.

The bug is introduced in #2121.

Can't be reproduced in over 1 millions requests after applying this
patch.
This commit is contained in:
罗泽轩 2020-11-25 14:32:11 +08:00 committed by GitHub
parent 1ad90f7206
commit 67eb787c38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 1 deletions

View File

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

View File

@ -39,6 +39,7 @@ routes:
-
uri: /hello
service_id: 1
id: 1
services:
-
id: 1
@ -62,6 +63,7 @@ hello world
routes:
-
uri: /hello
id: 1
service_id: 1111
services:
-
@ -84,6 +86,7 @@ failed to fetch service configuration by id: 1111
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
services:
@ -115,6 +118,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
@ -149,6 +153,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
@ -184,6 +189,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
service_id: 1
upstream:
@ -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]

View File

@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstreams:
@ -60,6 +61,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1111
upstreams:
@ -82,6 +84,7 @@ failed to find upstream by id: 1111
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstream:
@ -109,6 +112,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream_id: 1
upstreams:
@ -139,6 +143,7 @@ hello world
--- apisix_yaml
routes:
-
id: 1
uri: /get
upstream_id: 1
upstreams:

View File

@ -37,6 +37,7 @@ __DATA__
--- apisix_yaml
routes:
-
id: 1
uri: /hello
upstream:
nodes:
@ -82,6 +83,7 @@ use config_center: yaml
--- apisix_yaml
routes:
-
id: 1
uri: /hello
host: foo.com
upstream:
@ -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