Skip to content
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: watch responses may be incorrectly parsed in the case of ETCD being proxied by a load balancer like nginx #153

Closed
nic-6443 opened this issue Feb 18, 2022 · 0 comments · Fixed by #154

Comments

@nic-6443
Copy link
Contributor

We have encountered some problems in using apisix, because our etcd uses nginx as a proxy. When etcd returns event responses as http chunk after passing through nginx proxy, the following two situations may occur:

  1. the data of an event is larger than the proxy_buffer_size of nginx, the origin chunk will be split into two chunks by nginx and sent to apisix, resulting in the body_reader() getting an incomplete json, and then the parsing will fail.
  2. two consecutive events are merged into one chunk by nginx and sent to the client, which will also cause apisix to fail to parse the json.

local function read_watch()
while(1) do
body, err = res.body_reader()
if not body then
return nil, err
end
if not utils.is_empty_str(body) then
break
end
end
body, err = decode_json(body)

I think the root cause of the above problem is that apisix assumes that each chunk in the watch response is a complete event, in fact, a chunk may be a partial event or multiple events, so we should take these into account.

Since the raw data returned by etcd carries a newline at the end of each complete event, I think we can use newlines as a event splitter to solve the above problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant