bugfix: now ngx.req.socket(raw) returns proper error when there is some other "light thread" reading the request body.
This commit is contained in:
Родитель
ebf9cc8679
Коммит
fc03bfec34
|
@ -3149,7 +3149,15 @@ ngx_http_lua_req_socket(lua_State *L)
|
|||
lua_pushliteral(L, "nginx version too old");
|
||||
return 2;
|
||||
#else
|
||||
if (!r->request_body) {
|
||||
if (r->request_body) {
|
||||
if (r->request_body->rest > 0) {
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "pending request body reading in some "
|
||||
"other thread");
|
||||
return 2;
|
||||
}
|
||||
|
||||
} else {
|
||||
rb = ngx_pcalloc(r->pool, sizeof(ngx_http_request_body_t));
|
||||
if (rb == NULL) {
|
||||
return luaL_error(L, "out of memory");
|
||||
|
|
|
@ -5,7 +5,7 @@ use t::TestNginxLua;
|
|||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * 33;
|
||||
plan tests => repeat_each() * 36;
|
||||
|
||||
our $HtmlDir = html_dir;
|
||||
|
||||
|
@ -735,3 +735,47 @@ hello
|
|||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 14: pending request body reading
|
||||
--- config
|
||||
server_tokens off;
|
||||
location = /t {
|
||||
content_by_lua '
|
||||
ngx.thread.spawn(function ()
|
||||
ngx.req.read_body()
|
||||
end)
|
||||
|
||||
local sock, err = ngx.req.socket(true)
|
||||
if not sock then
|
||||
ngx.log(ngx.WARN, "server: failed to get raw req socket: ", err)
|
||||
return ngx.exit(444)
|
||||
end
|
||||
|
||||
local data, err = sock:receive(5)
|
||||
if not data then
|
||||
ngx.log(ngx.ERR, "failed to receive: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
local ok, err = sock:send("HTTP/1.1 200 OK\\r\\nContent-Length: 5\\r\\n\\r\\n" .. data)
|
||||
if not ok then
|
||||
ngx.log(ngx.ERR, "failed to send: ", err)
|
||||
return
|
||||
end
|
||||
';
|
||||
}
|
||||
|
||||
--- raw_request eval
|
||||
"GET /t HTTP/1.0\r
|
||||
Host: localhost\r
|
||||
Content-Length: 5\r
|
||||
\r
|
||||
hell"
|
||||
--- ignore_response
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
--- error_log
|
||||
server: failed to get raw req socket: pending request body reading in some other thread
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче