Skip to content
Merged
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
19 changes: 10 additions & 9 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,10 @@ patches](https://github.com/openresty/openresty/tree/master/patches).

Alternatively, ngx_lua can be manually compiled into Nginx:

1. LuaJIT can be downloaded from the [latest release of OpenResty's LuaJIT fork](https://github.com/openresty/luajit2/releases). The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above..
1. Download the latest version of the ngx_devel_kit (NDK) module [HERE](https://github.com/simplresty/ngx_devel_kit/tags).
1. Download the latest version of ngx_lua [HERE](https://github.com/openresty/lua-nginx-module/tags).
1. Download the latest version of Nginx [HERE](https://nginx.org/) (See [Nginx Compatibility](#nginx-compatibility))
1. LuaJIT can be downloaded from the [latest release of OpenResty's LuaJIT fork](https://github.com/openresty/luajit2/releases). The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above
1. Download the latest version of the ngx_devel_kit (NDK) module [HERE](https://github.com/simplresty/ngx_devel_kit/tags)
1. Download the latest version of ngx_lua [HERE](https://github.com/openresty/lua-nginx-module/tags)
1. Download the latest supported version of Nginx [HERE](https://nginx.org/) (See [Nginx Compatibility](#nginx-compatibility))

Build the source with this module:

Expand Down Expand Up @@ -413,7 +413,8 @@ The [openresty](https://groups.google.com/group/openresty) mailing list is for C
Code Repository
===============

The code repository of this project is hosted on github at [openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module).
The code repository of this project is hosted on GitHub at
[openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module).

[Back to TOC](#table-of-contents)

Expand Down Expand Up @@ -7625,7 +7626,7 @@ tcpsock:settimeout

Set the timeout value in milliseconds for subsequent socket operations ([connect](#tcpsockconnect), [receive](#tcpsockreceive), and iterators returned from [receiveuntil](#tcpsockreceiveuntil)).

Settings done by this method takes priority over those config directives, i.e., [lua_socket_connect_timeout](#lua_socket_connect_timeout), [lua_socket_send_timeout](#lua_socket_send_timeout), and [lua_socket_read_timeout](#lua_socket_read_timeout).
Settings done by this method take priority over those specified via config directives (i.e. [lua_socket_connect_timeout](#lua_socket_connect_timeout), [lua_socket_send_timeout](#lua_socket_send_timeout), and [lua_socket_read_timeout](#lua_socket_read_timeout)).

Note that this method does *not* affect the [lua_socket_keepalive_timeout](#lua_socket_keepalive_timeout) setting; the `timeout` argument to the [setkeepalive](#tcpsocksetkeepalive) method should be used for this purpose instead.

Expand All @@ -7640,12 +7641,12 @@ tcpsock:settimeouts

**context:** *rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua**

Sets the connect timeout thresold, send timeout threshold, and read timeout threshold, respetively, in milliseconds, for subsequent socket
Respectively sets the connect, send, and read timeout thresholds (in milliseconds) for subsequent socket
operations ([connect](#tcpsockconnect), [send](#tcpsocksend), [receive](#tcpsockreceive), and iterators returned from [receiveuntil](#tcpsockreceiveuntil)).

Settings done by this method takes priority over those config directives, i.e., [lua_socket_connect_timeout](#lua_socket_connect_timeout), [lua_socket_send_timeout](#lua_socket_send_timeout), and [lua_socket_read_timeout](#lua_socket_read_timeout).
Settings done by this method take priority over those specified via config directives (i.e. [lua_socket_connect_timeout](#lua_socket_connect_timeout), [lua_socket_send_timeout](#lua_socket_send_timeout), and [lua_socket_read_timeout](#lua_socket_read_timeout)).

You are recommended to use [settimeouts](#tcpsocksettimeouts) instead of [settimeout](#tcpsocksettimeout).
It is recommended to use [settimeouts](#tcpsocksettimeouts) instead of [settimeout](#tcpsocksettimeout).

Note that this method does *not* affect the [lua_socket_keepalive_timeout](#lua_socket_keepalive_timeout) setting; the `timeout` argument to the [setkeepalive](#tcpsocksetkeepalive) method should be used for this purpose instead.

Expand Down
19 changes: 10 additions & 9 deletions doc/HttpLuaModule.wiki
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,10 @@ patches].

Alternatively, ngx_lua can be manually compiled into Nginx:

# LuaJIT can be downloaded from the [https://github.com/openresty/luajit2/releases latest release of OpenResty's LuaJIT fork]. The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above..
# Download the latest version of the ngx_devel_kit (NDK) module [https://github.com/simplresty/ngx_devel_kit/tags HERE].
# Download the latest version of ngx_lua [https://github.com/openresty/lua-nginx-module/tags HERE].
# Download the latest version of Nginx [https://nginx.org/ HERE] (See [[#Nginx Compatibility|Nginx Compatibility]])
# LuaJIT can be downloaded from the [https://github.com/openresty/luajit2/releases latest release of OpenResty's LuaJIT fork]. The official LuaJIT 2.x releases are also supported, although performance will be significantly lower for reasons elaborated above
# Download the latest version of the ngx_devel_kit (NDK) module [https://github.com/simplresty/ngx_devel_kit/tags HERE]
# Download the latest version of ngx_lua [https://github.com/openresty/lua-nginx-module/tags HERE]
# Download the latest supported version of Nginx [https://nginx.org/ HERE] (See [[#Nginx Compatibility|Nginx Compatibility]])

Build the source with this module:

Expand Down Expand Up @@ -328,7 +328,8 @@ The [https://groups.google.com/group/openresty openresty] mailing list is for Ch

= Code Repository =

The code repository of this project is hosted on github at [https://github.com/openresty/lua-nginx-module openresty/lua-nginx-module].
The code repository of this project is hosted on GitHub at
[https://github.com/openresty/lua-nginx-module openresty/lua-nginx-module].

= Bugs and Patches =

Expand Down Expand Up @@ -6481,7 +6482,7 @@ This feature was first introduced in the <code>v0.5.0rc1</code> release.

Set the timeout value in milliseconds for subsequent socket operations ([[#tcpsock:connect|connect]], [[#tcpsock:receive|receive]], and iterators returned from [[#tcpsock:receiveuntil|receiveuntil]]).

Settings done by this method takes priority over those config directives, i.e., [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]].
Settings done by this method take priority over those specified via config directives (i.e. [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]]).

Note that this method does ''not'' affect the [[#lua_socket_keepalive_timeout|lua_socket_keepalive_timeout]] setting; the <code>timeout</code> argument to the [[#tcpsock:setkeepalive|setkeepalive]] method should be used for this purpose instead.

Expand All @@ -6493,12 +6494,12 @@ This feature was first introduced in the <code>v0.5.0rc1</code> release.

'''context:''' ''rewrite_by_lua*, access_by_lua*, content_by_lua*, ngx.timer.*, ssl_certificate_by_lua*, ssl_session_fetch_by_lua*''

Sets the connect timeout thresold, send timeout threshold, and read timeout threshold, respetively, in milliseconds, for subsequent socket
Respectively sets the connect, send, and read timeout thresholds (in milliseconds) for subsequent socket
operations ([[#tcpsock:connect|connect]], [[#tcpsock:send|send]], [[#tcpsock:receive|receive]], and iterators returned from [[#tcpsock:receiveuntil|receiveuntil]]).

Settings done by this method takes priority over those config directives, i.e., [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]].
Settings done by this method take priority over those specified via config directives (i.e. [[#lua_socket_connect_timeout|lua_socket_connect_timeout]], [[#lua_socket_send_timeout|lua_socket_send_timeout]], and [[#lua_socket_read_timeout|lua_socket_read_timeout]]).

You are recommended to use [[#tcpsock:settimeouts|settimeouts]] instead of [[#tcpsock:settimeout|settimeout]].
It is recommended to use [[#tcpsock:settimeouts|settimeouts]] instead of [[#tcpsock:settimeout|settimeout]].

Note that this method does ''not'' affect the [[#lua_socket_keepalive_timeout|lua_socket_keepalive_timeout]] setting; the <code>timeout</code> argument to the [[#tcpsock:setkeepalive|setkeepalive]] method should be used for this purpose instead.

Expand Down
4 changes: 2 additions & 2 deletions src/ngx_http_lua_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,

if (!ctx->cur_co_ctx->is_wrap) {
/*
* ended successful, coroutine.resume returns true plus
* ended successfully, coroutine.resume returns true plus
* any return values
*/
lua_pushboolean(next_co, success);
Expand Down Expand Up @@ -1520,7 +1520,7 @@ ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
if (orig_coctx->is_wrap) {
/*
* coroutine.wrap propagates errors
* to the parent
* to its parent coroutine
*/
next_coctx->propagate_error = 1;
continue;
Expand Down
58 changes: 48 additions & 10 deletions t/058-tcp-socket.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * 219;
plan tests => repeat_each() * 222;

our $HtmlDir = html_dir;

Expand Down Expand Up @@ -3643,7 +3643,45 @@ lua http cleanup reuse



=== TEST 60: options_table is nil
=== TEST 60: setkeepalive on socket already shutdown
--- config
location /t {
set $port $TEST_NGINX_MEMCACHED_PORT;

content_by_lua_block {
local sock = ngx.socket.tcp()
local port = ngx.var.port

local ok, err = sock:connect("127.0.0.1", port)
if not ok then
ngx.say("failed to connect: ", err)
return
end

ngx.say("connected: ", ok)

local ok, err = sock:close()
if not ok then
ngx.log(ngx.ERR, "failed to close socket: ", err)
return
end

local ok, err = sock:setkeepalive()
if not ok then
ngx.log(ngx.ERR, "failed to setkeepalive: ", err)
end
}
}
--- request
GET /t
--- response_body
connected: 1
--- error_log
failed to setkeepalive: closed



=== TEST 61: options_table is nil
--- config
location /t {
set $port $TEST_NGINX_MEMCACHED_PORT;
Expand Down Expand Up @@ -3693,7 +3731,7 @@ close: 1 nil



=== TEST 61: resolver send query failing immediately in connect()
=== TEST 62: resolver send query failing immediately in connect()
this case did not clear coctx->cleanup properly and would lead to memory invalid accesses.

this test case requires the following iptables rule to work properly:
Expand Down Expand Up @@ -3730,7 +3768,7 @@ qr{\[alert\] .*? send\(\) failed \(\d+: Operation not permitted\) while resolvin



=== TEST 62: the upper bound of port range should be 2^16 - 1
=== TEST 63: the upper bound of port range should be 2^16 - 1
--- config
location /t {
content_by_lua_block {
Expand All @@ -3749,7 +3787,7 @@ failed to connect: bad port number: 65536



=== TEST 63: send boolean and nil
=== TEST 64: send boolean and nil
--- config
location /t {
set $port $TEST_NGINX_SERVER_PORT;
Expand Down Expand Up @@ -3811,7 +3849,7 @@ received: truefalsenil



=== TEST 64: receiveany method in cosocket
=== TEST 65: receiveany method in cosocket
--- config
server_tokens off;
location = /t {
Expand Down Expand Up @@ -3900,7 +3938,7 @@ lua tcp socket read any



=== TEST 65: receiveany send data after read side closed
=== TEST 66: receiveany send data after read side closed
--- config
server_tokens off;
location = /t {
Expand Down Expand Up @@ -3944,7 +3982,7 @@ GET /t



=== TEST 66: receiveany with limited, max <= 0
=== TEST 67: receiveany with limited, max <= 0
--- config
location = /t {
set $port $TEST_NGINX_SERVER_PORT;
Expand Down Expand Up @@ -3980,7 +4018,7 @@ GET /t



=== TEST 67: receiveany with limited, max is larger than data
=== TEST 68: receiveany with limited, max is larger than data
--- config
server_tokens off;
location = /t {
Expand Down Expand Up @@ -4049,7 +4087,7 @@ lua tcp socket calling receiveany() method to read at most 128 bytes



=== TEST 68: receiveany with limited, max is smaller than data
=== TEST 69: receiveany with limited, max is smaller than data
--- config
server_tokens off;
location = /t {
Expand Down
59 changes: 1 addition & 58 deletions t/087-udp-socket.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua;

repeat_each(2);

plan tests => repeat_each() * (3 * blocks() + 14);
plan tests => repeat_each() * (3 * blocks() + 13);

our $HtmlDir = html_dir;

Expand Down Expand Up @@ -1006,63 +1006,6 @@ qr/runtime error: content_by_lua\(nginx\.conf:\d+\):14: bad request/
#set $port 5000;
set $port $TEST_NGINX_MEMCACHED_PORT;

content_by_lua '
local test = require "test"
if ngx.var.arg_reset then
local sock = test.new_sock()
local ok, err = sock:setpeername("127.0.0.1", ngx.var.port)
if not ok then
ngx.say("failed to set peer: ", err)
else
ngx.say("peer set")
end
return
end
local sock = test.get_sock()
sock:send("a")
';
}
--- user_files
>>> test.lua
module("test", package.seeall)

local sock

function new_sock()
sock = ngx.socket.udp()
return sock
end

function get_sock()
return sock
end
--- request
GET /main
--- response_body_like eval
qr/^peer set
<html.*?500 Internal Server Error/ms

--- error_log eval
qr/runtime error: content_by_lua\(nginx\.conf:\d+\):14: bad request/

--- no_error_log
[alert]



=== TEST 19: bad request tries to receive
--- http_config eval
"lua_package_path '$::HtmlDir/?.lua;./?.lua;;';"
--- config
server_tokens off;
location = /main {
echo_location /t?reset=1;
echo_location /t;
}
location /t {
#set $port 5000;
set $port $TEST_NGINX_MEMCACHED_PORT;

content_by_lua '
local test = require "test"
if ngx.var.arg_reset then
Expand Down
8 changes: 4 additions & 4 deletions t/091-coroutine.t
Original file line number Diff line number Diff line change
Expand Up @@ -1533,7 +1533,7 @@ co == co2: false
--- config
location = /t {
content_by_lua_block {
function f()
local function f()
local cnt = 0
for i = 1, 20 do
ngx.say("co yield: ", cnt)
Expand Down Expand Up @@ -1567,7 +1567,7 @@ co yield: 2
--- config
location = /t {
content_by_lua_block {
function f()
local function f()
local cnt = 0
for i = 1, 20 do
coroutine.yield(cnt, cnt + 1)
Expand Down Expand Up @@ -1601,7 +1601,7 @@ co yield: 2, 3
--- config
location = /t {
content_by_lua_block {
function f(step)
local function f(step)
local cnt = 0
for i = 1, 20 do
ngx.say("co yield: ", cnt)
Expand Down Expand Up @@ -1637,7 +1637,7 @@ co yield: 2
return 200;

header_filter_by_lua_block {
function f()
local function f()
local cnt = 0
for i = 1, 20 do
print("co yield: ", cnt)
Expand Down
Loading