Skip to content

Commit 97b9189

Browse files
authored
bugfix: when recreating balancer buffer, remove existing buffers first (#1770)
1 parent 172c214 commit 97b9189

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/ngx_http_lua_balancer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,13 @@ ngx_http_lua_ffi_balancer_recreate_request(ngx_http_request_t *r,
788788

789789
*err = NULL;
790790

791+
if (u->request_bufs != NULL && u->request_bufs != r->request_body->bufs) {
792+
/* u->request_bufs already contains a valid request buffer
793+
* remove it from chain first
794+
*/
795+
u->request_bufs = u->request_bufs->next;
796+
}
797+
791798
return u->create_request(r);
792799
}
793800

t/138-balancer.t

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,3 +524,43 @@ http next upstream, 2
524524
--- no_error_log
525525
failed to set more tries: reduced tries due to limit
526526
[alert]
527+
528+
529+
530+
=== TEST 17: recreate_request buffer bugfix
531+
--- http_config
532+
lua_package_path "../lua-resty-core/lib/?.lua;;";
533+
534+
server {
535+
listen 127.0.0.1:8888;
536+
537+
location / {
538+
return 200 "it works";
539+
}
540+
}
541+
542+
upstream foo {
543+
server 127.0.0.1:8888 max_fails=0;
544+
server 127.0.0.1:8889 max_fails=0 weight=9999;
545+
546+
balancer_by_lua_block {
547+
local bal = require "ngx.balancer"
548+
549+
assert(bal.recreate_request())
550+
}
551+
}
552+
553+
--- config
554+
location = /t {
555+
proxy_http_version 1.1;
556+
proxy_set_header Connection "";
557+
proxy_pass http://foo;
558+
}
559+
--- request
560+
GET /t
561+
--- error_code: 200
562+
--- error_log
563+
connect() failed (111: Connection refused) while connecting to upstream
564+
--- no_error_log
565+
upstream sent more data than specified in "Content-Length" header while reading upstream
566+
[alert]

0 commit comments

Comments
 (0)