File tree Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Original file line number Diff line number Diff line change @@ -3185,6 +3185,25 @@ ngx_stream_lua_socket_tcp_shutdown(lua_State *L)
3185
3185
return luaL_error (L , "no request found" );
3186
3186
}
3187
3187
3188
+ if (u == NULL
3189
+ || u -> peer .connection == NULL
3190
+ || (u -> read_closed && u -> write_closed ))
3191
+ {
3192
+ lua_pushnil (L );
3193
+ lua_pushliteral (L , "closed" );
3194
+ return 2 ;
3195
+ }
3196
+
3197
+ if (u -> write_closed ) {
3198
+ lua_pushnil (L );
3199
+ lua_pushliteral (L , "already shutdown" );
3200
+ return 2 ;
3201
+ }
3202
+
3203
+ if (u -> request != r ) {
3204
+ return luaL_error (L , "bad request" );
3205
+ }
3206
+
3188
3207
ctx = ngx_stream_lua_get_module_ctx (r , ngx_stream_lua_module );
3189
3208
if (ctx == NULL ) {
3190
3209
ngx_stream_lua_socket_handle_write_error (r , u ,
@@ -3212,25 +3231,6 @@ ngx_stream_lua_socket_tcp_shutdown(lua_State *L)
3212
3231
ctx -> eof = 1 ;
3213
3232
}
3214
3233
3215
- if (u == NULL
3216
- || u -> peer .connection == NULL
3217
- || (u -> read_closed && u -> write_closed ))
3218
- {
3219
- lua_pushnil (L );
3220
- lua_pushliteral (L , "closed" );
3221
- return 2 ;
3222
- }
3223
-
3224
- if (u -> write_closed ) {
3225
- lua_pushnil (L );
3226
- lua_pushliteral (L , "already shutdown" );
3227
- return 2 ;
3228
- }
3229
-
3230
- if (u -> request != r ) {
3231
- return luaL_error (L , "bad request" );
3232
- }
3233
-
3234
3234
ngx_stream_lua_socket_check_busy_connecting (r , u , L );
3235
3235
ngx_stream_lua_socket_check_busy_writing (r , u , L );
3236
3236
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua::Stream;
4
4
5
5
repeat_each(2 );
6
6
7
- plan tests => repeat_each() * 219 ;
7
+ plan tests => repeat_each() * 221 ;
8
8
9
9
our $ HtmlDir = html_dir;
10
10
@@ -3526,3 +3526,22 @@ orld
3526
3526
[ error ]
3527
3527
--- error_log
3528
3528
lua tcp socket calling receiveany () method to read at most 7 bytes
3529
+
3530
+
3531
+
3532
+ === TEST 67 : shutdown on a not connected socket correctly throws error
3533
+ --- stream_server_config
3534
+ lua_socket_connect_timeout 1s ;
3535
+ resolver $TEST_NGINX_RESOLVER ipv6 = off ;
3536
+ resolver_timeout 3s ;
3537
+
3538
+ content_by_lua_block {
3539
+ local sock = ngx .socket.tcp ()
3540
+
3541
+ local ok , err = sock :shutdown (' send' )
3542
+ ngx .log (ngx. ERR, ' shutdown on a not connected socket: ' , err)
3543
+
3544
+ }
3545
+
3546
+ --- error_log
3547
+ shutdown on a not connected socket : closed
You can’t perform that action at this time.
0 commit comments