Skip to content

Commit 93d1f30

Browse files
committed
bugfix: a followup fix for the previous commit.
1 parent afbfe4c commit 93d1f30

File tree

4 files changed

+41
-57
lines changed

4 files changed

+41
-57
lines changed

src/ngx_http_lua_socket_tcp.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,7 @@ ngx_http_lua_socket_tcp_settimeout(lua_State *L)
27122712

27132713
timeout = (ngx_int_t) lua_tonumber(L, 2);
27142714
if (timeout >> 31) {
2715-
return luaL_error(L, "timeout value too large");
2715+
return luaL_error(L, "bad timeout value");
27162716
}
27172717

27182718
lua_pushinteger(L, timeout);
@@ -2759,17 +2759,17 @@ ngx_http_lua_socket_tcp_settimeouts(lua_State *L)
27592759

27602760
connect_timeout = (ngx_int_t) lua_tonumber(L, 2);
27612761
if (connect_timeout >> 31) {
2762-
return luaL_error(L, "timeout value too large");
2762+
return luaL_error(L, "bad timeout value");
27632763
}
27642764

27652765
send_timeout = (ngx_int_t) lua_tonumber(L, 3);
27662766
if (send_timeout >> 31) {
2767-
return luaL_error(L, "timeout value too large");
2767+
return luaL_error(L, "bad timeout value");
27682768
}
27692769

27702770
read_timeout = (ngx_int_t) lua_tonumber(L, 4);
27712771
if (read_timeout >> 31) {
2772-
return luaL_error(L, "timeout value too large");
2772+
return luaL_error(L, "bad timeout value");
27732773
}
27742774

27752775
lua_rawseti(L, 1, SOCKET_READ_TIMEOUT_INDEX);

t/023-rewrite/tcp-socket-timeout.t

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Test::Nginx::Socket::Lua;
2424

2525
repeat_each(2);
2626

27-
plan tests => repeat_each() * (blocks() * 4 + 14);
27+
plan tests => repeat_each() * (blocks() * 4 + 8);
2828

2929
our $HtmlDir = html_dir;
3030

@@ -174,7 +174,7 @@ lua tcp socket connect timeout: 102
174174

175175

176176

177-
=== TEST 5: sock:settimeout(-1) does not override lua_socket_connect_timeout
177+
=== TEST 5: -1 is bad timeout value
178178
--- config
179179
server_tokens off;
180180
lua_socket_connect_timeout 102ms;
@@ -198,14 +198,12 @@ lua tcp socket connect timeout: 102
198198
}
199199
--- request
200200
GET /t5
201-
--- response_body
202-
failed to connect: timeout
201+
--- response_body_like chomp
202+
500 Internal Server Error
203203
--- error_log
204-
lua tcp socket connect timeout: 102
205-
--- no_error_log
206-
[error]
207-
[alert]
204+
bad timeout value
208205
--- timeout: 10
206+
--- error_code: 500
209207

210208

211209

@@ -371,7 +369,7 @@ lua tcp socket read timed out
371369

372370

373371

374-
=== TEST 10: sock:settimeout(-1) does not override lua_socket_read_timeout
372+
=== TEST 10: -1 is bad timeout value
375373
--- config
376374
server_tokens off;
377375
lua_socket_read_timeout 102ms;
@@ -385,8 +383,6 @@ lua tcp socket read timed out
385383
return
386384
end
387385
388-
ngx.say("connected: ", ok)
389-
390386
sock:settimeout(-1)
391387
392388
local line
@@ -402,13 +398,12 @@ lua tcp socket read timed out
402398
}
403399
--- request
404400
GET /t
405-
--- response_body
406-
connected: 1
407-
failed to receive: timeout
401+
--- response_body_like chomp
402+
500 Internal Server Error
408403
--- error_log
409-
lua tcp socket read timeout: 102
410-
lua tcp socket connect timeout: 60000
411-
lua tcp socket read timed out
404+
bad timeout value
405+
--- timeout: 10
406+
--- error_code: 500
412407

413408

414409

@@ -574,7 +569,7 @@ lua tcp socket write timed out
574569

575570

576571

577-
=== TEST 15: sock:settimeout(-1) does not override lua_socket_send_timeout
572+
=== TEST 15: -1 is bad timeout value
578573
--- config
579574
server_tokens off;
580575
lua_socket_send_timeout 102ms;
@@ -588,8 +583,6 @@ lua tcp socket write timed out
588583
return
589584
end
590585
591-
ngx.say("connected: ", ok)
592-
593586
sock:settimeout(-1)
594587
595588
local bytes
@@ -605,10 +598,9 @@ lua tcp socket write timed out
605598
}
606599
--- request
607600
GET /t
608-
--- response_body
609-
connected: 1
610-
failed to send: timeout
601+
--- response_body_like chomp
602+
500 Internal Server Error
611603
--- error_log
612-
lua tcp socket send timeout: 102
613-
lua tcp socket connect timeout: 60000
614-
lua tcp socket write timed out
604+
bad timeout value
605+
--- timeout: 10
606+
--- error_code: 500

t/065-tcp-socket-timeout.t

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ our $StapScript = $t::StapThread::StapScript;
2828

2929
repeat_each(2);
3030

31-
plan tests => repeat_each() * (blocks() * 4 + 11);
31+
plan tests => repeat_each() * (blocks() * 4 + 6);
3232

3333
our $HtmlDir = html_dir;
3434

@@ -159,7 +159,7 @@ lua tcp socket connect timed out
159159

160160

161161

162-
=== TEST 5: sock:settimeout(-1) does not override lua_socket_connect_timeout
162+
=== TEST 5: -1 is bad timeout value
163163
--- config
164164
server_tokens off;
165165
lua_socket_connect_timeout 102ms;
@@ -179,11 +179,11 @@ lua tcp socket connect timed out
179179
}
180180
--- request
181181
GET /t
182-
--- response_body
183-
failed to connect: timeout
182+
--- response_body_like chomp
183+
500 Internal Server Error
184184
--- error_log
185-
lua tcp socket connect timeout: 102
186-
lua tcp socket connect timed out
185+
bad timeout value
186+
--- error_code: 500
187187

188188

189189

@@ -342,7 +342,7 @@ lua tcp socket read timed out
342342

343343

344344

345-
=== TEST 10: sock:settimeout(-1) does not override lua_socket_read_timeout
345+
=== TEST 10: -1 is bad timeout value
346346
--- config
347347
server_tokens off;
348348
lua_socket_read_timeout 102ms;
@@ -356,8 +356,6 @@ lua tcp socket read timed out
356356
return
357357
end
358358
359-
ngx.say("connected: ", ok)
360-
361359
sock:settimeout(-1)
362360
363361
local line
@@ -371,13 +369,11 @@ lua tcp socket read timed out
371369
}
372370
--- request
373371
GET /t
374-
--- response_body
375-
connected: 1
376-
failed to receive: timeout
372+
--- response_body_like chomp
373+
500 Internal Server Error
374+
--- error_code: 500
377375
--- error_log
378-
lua tcp socket read timeout: 102
379-
lua tcp socket connect timeout: 60000
380-
lua tcp socket read timed out
376+
bad timeout value
381377

382378

383379

@@ -563,8 +559,6 @@ lua tcp socket write timed out
563559
return
564560
end
565561
566-
ngx.say("connected: ", ok)
567-
568562
sock:settimeout(-1)
569563
570564
local bytes
@@ -578,13 +572,11 @@ lua tcp socket write timed out
578572
}
579573
--- request
580574
GET /t
581-
--- response_body
582-
connected: 1
583-
failed to send: timeout
575+
--- response_body_like chomp
576+
500 Internal Server Error
584577
--- error_log
585-
lua tcp socket send timeout: 102
586-
lua tcp socket connect timeout: 60000
587-
lua tcp socket write timed out
578+
bad timeout value
579+
--- error_code: 500
588580

589581

590582

@@ -1021,6 +1013,6 @@ close: 1 nil
10211013
GET /t
10221014
--- response_body_like
10231015
settimeout: ok
1024-
failed to set timeout: lua tcp socket timeout 2147483648(?:\.\d+)? will overflow
1016+
failed to set timeout: bad timeout value
10251017
--- no_error_log
10261018
[error]

t/147-tcp-socket-timeouts.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ failed to receive a line: closed []
560560
GET /t
561561
--- response_body_like
562562
settimeouts: ok
563-
failed to set timeouts: timeout value too large
563+
failed to set timeouts: bad timeout value
564564
--- no_error_log
565565
[error]
566566

@@ -591,7 +591,7 @@ failed to set timeouts: timeout value too large
591591
GET /t
592592
--- response_body_like
593593
settimeouts: ok
594-
failed to set timeouts: timeout value too large
594+
failed to set timeouts: bad timeout value
595595
--- no_error_log
596596
[error]
597597

@@ -622,6 +622,6 @@ failed to set timeouts: timeout value too large
622622
GET /t
623623
--- response_body_like
624624
settimeouts: ok
625-
failed to set timeouts: timeout value too large
625+
failed to set timeouts: bad timeout value
626626
--- no_error_log
627627
[error]

0 commit comments

Comments
 (0)