You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by sp...@apache.org on 2022/08/17 09:29:05 UTC
[apisix] 03/12: fix(upstream): http connection was put into https connection pool (#7466)
This is an automated email from the ASF dual-hosted git repository.
spacewander pushed a commit to branch release/2.13
in repository https://gitbox.apache.org/repos/asf/apisix.git
commit 1892d997eff7ccbebe8e00ba930fa3db27997540
Author: 罗泽轩 <sp...@gmail.com>
AuthorDate: Fri Jul 15 14:06:28 2022 +0800
fix(upstream): http connection was put into https connection pool (#7466)
This bug is introduced in https://github.com/apache/apisix/commit/3dddf41382e8916ce92d7e29c1e8e6d86b821304
Signed-off-by: spacewander <sp...@gmail.com>
---
apisix/balancer.lua | 1 +
t/node/upstream-keepalive-pool.t | 103 +++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+)
diff --git a/apisix/balancer.lua b/apisix/balancer.lua
index 5eb9d2777..d7935a661 100644
--- a/apisix/balancer.lua
+++ b/apisix/balancer.lua
@@ -289,6 +289,7 @@ do
local size = keepalive_pool.size
local requests = keepalive_pool.requests
+ core.table.clear(pool_opt)
pool_opt.pool_size = size
local scheme = up_conf.scheme
diff --git a/t/node/upstream-keepalive-pool.t b/t/node/upstream-keepalive-pool.t
index 084522b4e..26f9306d0 100644
--- a/t/node/upstream-keepalive-pool.t
+++ b/t/node/upstream-keepalive-pool.t
@@ -635,3 +635,106 @@ qr/lua balancer: keepalive create pool, .*/
qr/^lua balancer: keepalive create pool, crc32: \S+, size: 8
lua balancer: keepalive create pool, crc32: \S+, size: 4
$/
+
+
+
+=== TEST 14: upstreams with SNI, then without SNI
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin")
+ local test = require("lib.test_admin").test
+ local json = require("toolkit.json")
+
+ local code, body = test('/apisix/admin/upstreams/1',
+ ngx.HTTP_PUT,
+ [[{
+ "scheme": "https",
+ "type": "roundrobin",
+ "nodes": {
+ "127.0.0.1:1983": 1
+ },
+ "pass_host": "rewrite",
+ "upstream_host": "a.com",
+ "keepalive_pool": {
+ "size": 4
+ }
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ ngx.print(body)
+ return
+ end
+
+ local data = {
+ scheme = "http",
+ type = "roundrobin",
+ nodes = {
+ ["127.0.0.1:1980"] = 1,
+ },
+ pass_host = "rewrite",
+ upstream_host = "b.com",
+ keepalive_pool = {
+ size = 8
+ }
+ }
+ local code, body = test('/apisix/admin/upstreams/2',
+ ngx.HTTP_PUT,
+ json.encode(data)
+ )
+ if code >= 300 then
+ ngx.status = code
+ ngx.print(body)
+ return
+ end
+
+ for i = 1, 2 do
+ local code, body = test('/apisix/admin/routes/' .. i,
+ ngx.HTTP_PUT,
+ [[{
+ "uri":"/hello/]] .. i .. [[",
+ "plugins": {
+ "proxy-rewrite": {
+ "uri": "/hello"
+ }
+ },
+ "upstream_id": ]] .. i .. [[
+ }]])
+ if code >= 300 then
+ ngx.status = code
+ ngx.print(body)
+ return
+ end
+ end
+ }
+ }
+--- response_body
+
+
+
+=== TEST 15: hit
+--- config
+ location /t {
+ content_by_lua_block {
+ local http = require "resty.http"
+ local uri = "http://127.0.0.1:" .. ngx.var.server_port
+ for i = 0, 1 do
+ local idx = i % 2 + 1
+ local httpc = http.new()
+ local res, err = httpc:request_uri(uri .. "/hello/" .. idx)
+ local res, err = httpc:request_uri(uri)
+ if not res then
+ ngx.say(err)
+ return
+ end
+ ngx.print(res.body)
+ end
+ }
+ }
+--- grep_error_log eval
+qr/lua balancer: keepalive create pool, .*/
+--- grep_error_log_out eval
+qr/^lua balancer: keepalive create pool, crc32: \S+, size: 4
+lua balancer: keepalive create pool, crc32: \S+, size: 8
+$/