Skip to content

Upstream timeout leads to mixed up responses #200

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/ledge/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ local function fetch_from_origin(self)
else
res.status = 503
end
httpc:close()
return res
end

Expand Down Expand Up @@ -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

Expand Down
46 changes: 43 additions & 3 deletions t/02-integration/upstream.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
Expand Down