Skip to content

Commit 1b702e5

Browse files
committed
added error logs for socket timeout errors.
1 parent 78ed3f5 commit 1b702e5

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

src/ngx_http_lua_socket.c

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,7 @@ ngx_http_lua_socket_tcp_receive(lua_State *L)
886886

887887
if (u == NULL || u->peer.connection == NULL || u->ft_type || u->eof) {
888888
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
889-
"attemp to receive data on a closed socket: u:%p, c:%p, "
889+
"attempt to receive data on a closed socket: u:%p, c:%p, "
890890
"ft:%ui eof:%ud",
891891
u, u ? u->peer.connection : NULL, u ? u->ft_type : 0,
892892
u ? u->eof : 0);
@@ -1402,7 +1402,7 @@ ngx_http_lua_socket_tcp_send(lua_State *L)
14021402

14031403
if (u == NULL || u->peer.connection == NULL || u->ft_type || u->eof) {
14041404
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1405-
"attemp to send data on a closed socket: u:%p, c:%p, "
1405+
"attempt to send data on a closed socket: u:%p, c:%p, "
14061406
"ft:%ui eof:%ud",
14071407
u, u ? u->peer.connection : NULL, u ? u->ft_type : 0,
14081408
u ? u->eof : 0);
@@ -1709,6 +1709,9 @@ ngx_http_lua_socket_read_handler(ngx_http_request_t *r,
17091709
"lua socket read handler");
17101710

17111711
if (c->read->timedout) {
1712+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1713+
"lua socket read timed out");
1714+
17121715
ngx_http_lua_socket_handle_error(r, u, NGX_HTTP_LUA_SOCKET_FT_TIMEOUT);
17131716
return;
17141717
}
@@ -1731,6 +1734,9 @@ ngx_http_lua_socket_send_handler(ngx_http_request_t *r,
17311734
"lua socket send handler");
17321735

17331736
if (c->write->timedout) {
1737+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1738+
"lua socket write timed out");
1739+
17341740
ngx_http_lua_socket_handle_error(r, u, NGX_HTTP_LUA_SOCKET_FT_TIMEOUT);
17351741
return;
17361742
}
@@ -1895,6 +1901,19 @@ ngx_http_lua_socket_connected_handler(ngx_http_request_t *r,
18951901
c = u->peer.connection;
18961902

18971903
if (c->write->timedout) {
1904+
1905+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1906+
"lua socket connect timed out");
1907+
1908+
ngx_http_lua_socket_handle_error(r, u, NGX_HTTP_LUA_SOCKET_FT_TIMEOUT);
1909+
return;
1910+
}
1911+
1912+
if (c->read->timedout) {
1913+
1914+
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
1915+
"lua socket connect timed out");
1916+
18981917
ngx_http_lua_socket_handle_error(r, u, NGX_HTTP_LUA_SOCKET_FT_TIMEOUT);
18991918
return;
19001919
}

t/058-tcp-socket.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use Test::Nginx::Socket;
55

66
repeat_each(2);
77

8-
plan tests => repeat_each() * (blocks() * 2 + 4);
8+
plan tests => repeat_each() * (blocks() * 2 + 5);
99

1010
our $HtmlDir = html_dir;
1111

@@ -185,8 +185,8 @@ GET /t
185185
failed to connect: no resolver defined to resolve "agentzh.org"
186186
connected: nil
187187
failed to send request: closed
188-
--- no_error_log
189-
[error]
188+
--- error_log
189+
attempt to send data on a closed socket:
190190
191191
192192

0 commit comments

Comments
 (0)