From 80e04821bc86ef92e03d757f97713bfd4ec2a5e7 Mon Sep 17 00:00:00 2001 From: jinhua luo Date: Wed, 17 May 2023 19:09:32 +0800 Subject: [PATCH] fix(etcd): reuse cli and enable keepalive (#9420) --- apisix/cli/snippet.lua | 3 +++ apisix/core/etcd.lua | 4 +--- t/core/config_etcd.t | 1 - t/core/etcd.t | 32 -------------------------------- 4 files changed, 4 insertions(+), 36 deletions(-) diff --git a/apisix/cli/snippet.lua b/apisix/cli/snippet.lua index ca7ed3f7c59a..95069a0ab263 100644 --- a/apisix/cli/snippet.lua +++ b/apisix/cli/snippet.lua @@ -28,6 +28,9 @@ upstream apisix_conf_backend { local conf_server = require("apisix.conf_server") conf_server.balancer() } + keepalive 320; + keepalive_requests 1000; + keepalive_timeout 60s; } {% if trusted_ca_cert then %} diff --git a/apisix/core/etcd.lua b/apisix/core/etcd.lua index 99e4bbb6b7ab..b52517cd40b5 100644 --- a/apisix/core/etcd.lua +++ b/apisix/core/etcd.lua @@ -372,9 +372,7 @@ do return nil, nil, err end - if tmp_etcd_cli.use_grpc then - etcd_cli = tmp_etcd_cli - end + etcd_cli = tmp_etcd_cli return tmp_etcd_cli, prefix end diff --git a/t/core/config_etcd.t b/t/core/config_etcd.t index 380b82522138..666d001b272b 100644 --- a/t/core/config_etcd.t +++ b/t/core/config_etcd.t @@ -266,7 +266,6 @@ qr/etcd auth failed/ etcd auth failed etcd auth failed etcd auth failed -etcd auth failed diff --git a/t/core/etcd.t b/t/core/etcd.t index eaa425ec6b15..c0715de7b06b 100644 --- a/t/core/etcd.t +++ b/t/core/etcd.t @@ -401,35 +401,3 @@ qr/init_by_lua:\d+: \S+/ init_by_lua:12: ab init_by_lua:19: 200 init_by_lua:26: 404 - - - -=== TEST 8: error handling in server_version ---- yaml_config -deployment: - role: traditional - role_traditional: - config_provider: etcd - etcd: - host: - - "http://127.0.0.1:2379" - prefix: "/apisix" ---- config - location /t { - content_by_lua_block { - local etcd_lib = require("resty.etcd") - -- the mock won't take effect when using gRPC because the connection will be cached - etcd_lib.new = function() - return nil, "ouch" - end - local etcd = require("apisix.core.etcd") - local res, err = etcd.server_version() - ngx.say(err) - } - } ---- request -GET /t ---- response_body -ouch ---- error_log -failed to get server_info from etcd