diff --git a/kong/clustering/control_plane.lua b/kong/clustering/control_plane.lua index c41e1b633ee6..d0b8ee2ac6df 100644 --- a/kong/clustering/control_plane.lua +++ b/kong/clustering/control_plane.lua @@ -3,7 +3,6 @@ local _MT = { __index = _M, } local semaphore = require("ngx.semaphore") -local ws_server = require("resty.websocket.server") local cjson = require("cjson.safe") local declarative = require("kong.db.declarative") local utils = require("kong.tools.utils") @@ -44,10 +43,6 @@ local ngx_ERR = ngx.ERR local ngx_OK = ngx.OK local ngx_ERROR = ngx.ERROR local ngx_CLOSE = ngx.HTTP_CLOSE -local WS_OPTS = { - timeout = constants.CLUSTERING_TIMEOUT, - max_payload_len = kong.configuration.cluster_max_payload, -} local PING_INTERVAL = constants.CLUSTERING_PING_INTERVAL local PING_WAIT = PING_INTERVAL * 1.5 local CLUSTERING_SYNC_STATUS = constants.CLUSTERING_SYNC_STATUS @@ -300,7 +295,7 @@ function _M:handle_cp_websocket() ngx_exit(400) end - local wb, err = ws_server:new(WS_OPTS) + local wb, err = clustering_utils.connect_dp() if not wb then ngx_log(ngx_ERR, _log_prefix, "failed to perform server side websocket handshake: ", err, log_suffix) return ngx_exit(ngx_CLOSE) diff --git a/kong/clustering/utils.lua b/kong/clustering/utils.lua index 9541bcef1ad5..3188096f145e 100644 --- a/kong/clustering/utils.lua +++ b/kong/clustering/utils.lua @@ -6,6 +6,7 @@ local ssl = require("ngx.ssl") local ocsp = require("ngx.ocsp") local http = require("resty.http") local ws_client = require("resty.websocket.client") +local ws_server = require("resty.websocket.server") local type = type local tonumber = tonumber @@ -390,4 +391,9 @@ function _M.connect_cp(endpoint, conf, cert, cert_key, protocols) end +function _M.connect_dp() + return ws_server:new(WS_OPTS) +end + + return _M diff --git a/kong/clustering/wrpc_control_plane.lua b/kong/clustering/wrpc_control_plane.lua index 2cedcc2faa20..5ebc5a6150e4 100644 --- a/kong/clustering/wrpc_control_plane.lua +++ b/kong/clustering/wrpc_control_plane.lua @@ -3,7 +3,6 @@ local _MT = { __index = _M, } local semaphore = require("ngx.semaphore") -local ws_server = require("resty.websocket.server") local cjson = require("cjson.safe") local declarative = require("kong.db.declarative") local constants = require("kong.constants") @@ -35,11 +34,6 @@ local ngx_NOTICE = ngx.NOTICE local ngx_WARN = ngx.WARN local ngx_ERR = ngx.ERR local ngx_CLOSE = ngx.HTTP_CLOSE -local MAX_PAYLOAD = constants.CLUSTERING_MAX_PAYLOAD -local WS_OPTS = { - timeout = constants.CLUSTERING_TIMEOUT, - max_payload_len = MAX_PAYLOAD, -} local CLUSTERING_SYNC_STATUS = constants.CLUSTERING_SYNC_STATUS local _log_prefix = "[wrpc-clustering] " @@ -216,7 +210,7 @@ function _M:handle_cp_websocket() local wb do local err - wb, err = ws_server:new(WS_OPTS) + wb, err = clustering_utils.connect_dp() if not wb then ngx_log(ngx_ERR, _log_prefix, "failed to perform server side websocket handshake: ", err, log_suffix) return ngx_exit(ngx_CLOSE)