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)
31853185 return luaL_error (L , "no request found" );
31863186 }
31873187
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+
31883207 ctx = ngx_stream_lua_get_module_ctx (r , ngx_stream_lua_module );
31893208 if (ctx == NULL ) {
31903209 ngx_stream_lua_socket_handle_write_error (r , u ,
@@ -3212,25 +3231,6 @@ ngx_stream_lua_socket_tcp_shutdown(lua_State *L)
32123231 ctx -> eof = 1 ;
32133232 }
32143233
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-
32343234 ngx_stream_lua_socket_check_busy_connecting (r , u , L );
32353235 ngx_stream_lua_socket_check_busy_writing (r , u , L );
32363236
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua::Stream;
44
55repeat_each(2 );
66
7- plan tests => repeat_each() * 219 ;
7+ plan tests => repeat_each() * 221 ;
88
99our $ HtmlDir = html_dir;
1010
@@ -3526,3 +3526,22 @@ orld
35263526[ error ]
35273527--- error_log
35283528lua 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