-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug: upstream nodes was not updated correctly by service discover #9805
Comments
thx your PR |
Could you please share your whole |
ok let me give the detail later |
@shreemaan-abhishek hi, i add the detail in Steps to Reproduce, can have a try |
Thanks, @ZhangShangyu, I was able to reproduce this. But I am unsure how to provide a more straightforward way to test this case. Can you think of a way to simplify the testing process for PR #9806? However, the way you have used the service discovery integration is the recommended way to use it |
I will be taking up this task and the PR, @Revolyssup , can you please assign me this ? |
@ZhangShangyu Good job! |
I would like to add to the explanation.
Is my explanation correct?? CC : @monkeyDluffy6017 @Sn0rt @shreemaan-abhishek |
@shreemaan-abhishek , can this be closed?? |
considered resolved |
Current Behavior
Bug description:
We have implement a service discover plugin to meet this requirement:
for example:
a.myhost.com should route to ip A
b.myhost.com should route to ip B
c.myhost.com should route to ip C
and so on
the service discover plugin demo is like this:
then create a service and route for it
do some requests to a.myhost.com and b.myhost.com,
magic happened, the upstream ip is not correct! seems like ABA problem
root cause:
1.upstream_conf is from cache
in the apisix source code
https://github.com/apache/apisix/blob/release/3.4/apisix/init.lua#L631C24-L631C43
https://github.com/apache/apisix/blob/release/3.4/apisix/plugin.lua#L634
if route.value.service_id then will call plugin.merge_service_route
plugin.merge_service_route
will use a lrucache by service_conf key and verison2. cached upstream_conf is used in set_upstream
https://github.com/apache/apisix/blob/release/3.4/apisix/init.lua#L478
https://github.com/apache/apisix/blob/release/3.4/apisix/init.lua#L478
3. compare cached upstream_conf original_node and service discover new nodes
https://github.com/apache/apisix/blob/release/3.4/apisix/upstream.lua#L277
https://github.com/apache/apisix/blob/release/3.4/apisix/utils/upstream.lua#L37
4. update upstream_conf by compare result
https://github.com/apache/apisix/blob/release/3.4/apisix/upstream.lua#L285
https://github.com/apache/apisix/blob/release/3.4/apisix/upstream.lua#L336
if original_nodes is same as new nodes, it will fill_node_info to old cached upstream_conf, everything is ok
if original_node is not the same as new_nodes, update nodes to new nodes, then clone a new_up_conf,
after this it will fill_node_info to new_up_conf
the bug cause is here, the old cached upstream_conf.original_nodes is not updated by fill_node_info, because new_up_conf is another address by clone
for example
solution
call fill_node_info before clone to new_up_conf, so the cached up_conf original_node will update
Expected Behavior
No response
Error Logs
No response
Steps to Reproduce
init.lua
schema.lua
config.yaml config nginx work to 1 and enable demo_discover plugin
apisix.yaml config route and service
you can see the fifth time access log a.myhost.com get wrong upstream 127.0.0.1:2222
Environment
The text was updated successfully, but these errors were encountered: