From cdb2499bc78dd3126180a79d8cada8f0bceb21f2 Mon Sep 17 00:00:00 2001 From: Christian Meilke Date: Fri, 30 Apr 2021 13:32:43 +0200 Subject: [PATCH 1/2] Fixed a bug with mixed up responses on timeout 524s --- lib/ledge/handler.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/ledge/handler.lua b/lib/ledge/handler.lua index f65fd7c5..96c64cf9 100644 --- a/lib/ledge/handler.lua +++ b/lib/ledge/handler.lua @@ -400,6 +400,7 @@ local function fetch_from_origin(self) else res.status = 503 end + httpc:close() return res end @@ -471,6 +472,7 @@ local function fetch_from_origin(self) if not origin then ngx_log(ngx_ERR, err) res.status = 524 + upstream_client:close() return res end From 8bd36c933d7468f6780d2cb9f8b76d580ea5601d Mon Sep 17 00:00:00 2001 From: Christian Meilke Date: Fri, 7 May 2021 10:31:49 +0200 Subject: [PATCH 2/2] Test for bugfix with mixed up responses on timeout 524s --- t/02-integration/upstream.t | 46 ++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/t/02-integration/upstream.t b/t/02-integration/upstream.t index dc9d6d08..e1fabcff 100644 --- a/t/02-integration/upstream.t +++ b/t/02-integration/upstream.t @@ -39,8 +39,48 @@ GET /upstream_prx --- error_log timeout +=== TEST 2: Short read timeout does not result in responses getting mixed up +--- http_config eval: $::HttpConfig +--- config +location /upstream_prx { + rewrite ^(.*)_prx$ $1 break; + content_by_lua_block { + require("ledge").create_handler({ + upstream_send_timeout = 5000, + upstream_connect_timeout = 5000, + upstream_read_timeout = 100, + }):run() + } +} + +location /other_prx { + rewrite ^(.*)_prx$ $1 break; + content_by_lua_block { + require("ledge").create_handler({}):run() + } +} + +location /upstream { + content_by_lua_block { + ngx.sleep(1) + ngx.say("upstream") + } +} + +location /other { + content_by_lua_block { + ngx.say("other") + } +} +--- request eval +["GET /upstream_prx", "GET /other_prx", "GET /other_prx", "GET /other_prx"] +--- error_code eval +[524, 200, 200, 200] +--- response_body eval +["", "other\n", "other\n", "other\n"] + -=== TEST 2: No upstream results in a 503. +=== TEST 3: No upstream results in a 503. --- http_config eval: $::HttpConfig --- config location /upstream_prx { @@ -59,7 +99,7 @@ GET /upstream_prx upstream connection failed: -=== TEST 3: No port results in 503 +=== TEST 4: No port results in 503 --- http_config eval: $::HttpConfig --- config location /upstream_prx { @@ -79,7 +119,7 @@ GET /upstream_prx upstream connection failed: -=== TEST 4: No port with unix socket works +=== TEST 5: No port with unix socket works --- http_config eval: $::HttpConfig --- config listen unix:$TEST_NGINX_SOCKET_DIR/nginx.sock;