This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 6ddca1025 fix(xRPC): don't keepalive (#7009)
6ddca1025 is described below

commit 6ddca102503a52822407301fdffb869e32fe59e9
Author: 罗泽轩 <spacewander...@gmail.com>
AuthorDate: Thu May 12 16:02:09 2022 +0800

    fix(xRPC): don't keepalive (#7009)
    
    We choose not to keepalive the xRPC connection (like Nginx's stream proxy):
    1. the TCP connection is probably stateful
    2. if there is not downstream, the heartbeat from the upstream is not
       replied, which will cause the connection to close.
    Signed-off-by: spacewander <spacewander...@gmail.com>
    
    Signed-off-by: spacewander <spacewander...@gmail.com>
---
 apisix/stream/xrpc/protocols/redis/init.lua           |  4 ++--
 apisix/stream/xrpc/runner.lua                         |  6 ++----
 apisix/stream/xrpc/sdk.lua                            | 12 +++---------
 t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua |  6 ++----
 t/xrpc/pingpong.t                                     |  3 +++
 5 files changed, 12 insertions(+), 19 deletions(-)

diff --git a/apisix/stream/xrpc/protocols/redis/init.lua 
b/apisix/stream/xrpc/protocols/redis/init.lua
index 2635cca71..24ca98f0c 100644
--- a/apisix/stream/xrpc/protocols/redis/init.lua
+++ b/apisix/stream/xrpc/protocols/redis/init.lua
@@ -353,8 +353,8 @@ function _M.connect_upstream(session, ctx)
 end
 
 
-function _M.disconnect_upstream(session, upstream, upstream_broken)
-    sdk.disconnect_upstream(upstream, session.upstream_conf, upstream_broken)
+function _M.disconnect_upstream(session, upstream)
+    sdk.disconnect_upstream(upstream, session.upstream_conf)
 end
 
 
diff --git a/apisix/stream/xrpc/runner.lua b/apisix/stream/xrpc/runner.lua
index 22cb62d03..7296a69b7 100644
--- a/apisix/stream/xrpc/runner.lua
+++ b/apisix/stream/xrpc/runner.lua
@@ -52,7 +52,7 @@ local function close_session(session, protocol)
         upstream_ctx.closed = true
 
         local up = upstream_ctx.upstream
-        protocol.disconnect_upstream(session, up, upstream_ctx.broken)
+        protocol.disconnect_upstream(session, up)
     end
 
     local upstream_ctxs = session._upstream_ctxs
@@ -61,7 +61,7 @@ local function close_session(session, protocol)
             upstream_ctx.closed = true
 
             local up = upstream_ctx.upstream
-            protocol.disconnect_upstream(session, up, upstream_ctx.broken)
+            protocol.disconnect_upstream(session, up)
         end
     end
 
@@ -162,7 +162,6 @@ local function open_upstream(protocol, session, ctx)
 
     local up_ctx = {
         upstream = upstream,
-        broken = false,
         closed = false,
     }
     if key then
@@ -239,7 +238,6 @@ function _M.run(protocol, conn_ctx)
             end
 
             if status == DECLINED then
-                up_ctx.broken = true
                 break
             end
 
diff --git a/apisix/stream/xrpc/sdk.lua b/apisix/stream/xrpc/sdk.lua
index eb70a4018..65bbe4c40 100644
--- a/apisix/stream/xrpc/sdk.lua
+++ b/apisix/stream/xrpc/sdk.lua
@@ -72,19 +72,13 @@ end
 
 
 ---
--- Returns disconnected xRPC upstream socket according to the configuration
+-- Disconnect xRPC upstream socket according to the configuration
 --
 -- @function xrpc.sdk.disconnect_upstream
 -- @tparam table upstream xRPC upstream socket
 -- @tparam table up_conf upstream configuration
--- @tparam boolean upstream_broken whether the upstream is already broken
-function _M.disconnect_upstream(upstream, up_conf, upstream_broken)
-    if upstream_broken then
-        upstream:close()
-    else
-        -- TODO: support keepalive according to the up_conf
-        upstream:setkeepalive()
-    end
+function _M.disconnect_upstream(upstream, up_conf)
+    return upstream:close()
 end
 
 
diff --git a/t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua 
b/t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
index 212cd6302..56b32fb31 100644
--- a/t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
+++ b/t/xrpc/apisix/stream/xrpc/protocols/pingpong/init.lua
@@ -190,11 +190,9 @@ function _M.connect_upstream(session, ctx)
 end
 
 
-function _M.disconnect_upstream(session, upstream, upstream_broken)
+function _M.disconnect_upstream(session, upstream)
     -- disconnect upstream created by connect_upstream
-    -- the upstream_broken flag is used to indicate whether the upstream is
-    -- already broken
-    sdk.disconnect_upstream(upstream, session.upstream_conf, upstream_broken)
+    sdk.disconnect_upstream(upstream, session.upstream_conf)
 end
 
 
diff --git a/t/xrpc/pingpong.t b/t/xrpc/pingpong.t
index 97c192ed6..64e4e055a 100644
--- a/t/xrpc/pingpong.t
+++ b/t/xrpc/pingpong.t
@@ -152,6 +152,9 @@ pp\x01\x00\x00\x00\x00\x00\x00\x00"
 "pp\x02\x00\x00\x00\x00\x00\x00\x03ABC" x 3
 --- response_body eval
 "pp\x02\x00\x00\x00\x00\x00\x00\x03ABC" x 3
+--- log_level: debug
+--- no_error_log
+stream lua tcp socket set keepalive
 --- stream_conf_enable
 
 

Reply via email to