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 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;