@@ -30,16 +30,12 @@ static ssize_t ngx_http_lua_pipe_fd_read(ngx_connection_t *c, u_char *buf,
30
30
size_t size );
31
31
static ssize_t ngx_http_lua_pipe_fd_write (ngx_connection_t * c , u_char * buf ,
32
32
size_t size );
33
- static ngx_int_t ngx_http_lua_pipe_close_helper (
34
- ngx_http_lua_pipe_ctx_t * pipe_ctx , ngx_event_t * ev , int forced );
35
- static ngx_int_t ngx_http_lua_pipe_close_stdin (ngx_http_lua_pipe_t * pipe ,
36
- int forced );
37
- static ngx_int_t ngx_http_lua_pipe_close_stdout (ngx_http_lua_pipe_t * pipe ,
38
- int forced );
39
- static ngx_int_t ngx_http_lua_pipe_close_stderr (ngx_http_lua_pipe_t * pipe ,
40
- int forced );
41
- static void ngx_http_lua_pipe_proc_finalize (ngx_http_lua_ffi_pipe_proc_t * proc ,
42
- int forced );
33
+ static void ngx_http_lua_pipe_close_helper (
34
+ ngx_http_lua_pipe_ctx_t * pipe_ctx , ngx_event_t * ev );
35
+ static void ngx_http_lua_pipe_close_stdin (ngx_http_lua_pipe_t * pipe );
36
+ static void ngx_http_lua_pipe_close_stdout (ngx_http_lua_pipe_t * pipe );
37
+ static void ngx_http_lua_pipe_close_stderr (ngx_http_lua_pipe_t * pipe );
38
+ static void ngx_http_lua_pipe_proc_finalize (ngx_http_lua_ffi_pipe_proc_t * proc );
43
39
static ngx_int_t ngx_http_lua_pipe_get_lua_ctx (ngx_http_request_t * r ,
44
40
ngx_http_lua_ctx_t * * ctx , u_char * errbuf , size_t * errbuf_size );
45
41
static void ngx_http_lua_pipe_put_error (ngx_http_lua_pipe_ctx_t * pipe_ctx ,
@@ -121,7 +117,8 @@ enum {
121
117
PIPE_ERR_NOMEM ,
122
118
PIPE_ERR_TIMEOUT ,
123
119
PIPE_ERR_ADD_READ_EV ,
124
- PIPE_ERR_ADD_WRITE_EV
120
+ PIPE_ERR_ADD_WRITE_EV ,
121
+ PIPE_ERR_ABORTED
125
122
};
126
123
127
124
@@ -914,26 +911,27 @@ ngx_http_lua_ffi_pipe_spawn(ngx_http_lua_ffi_pipe_proc_t *proc,
914
911
}
915
912
916
913
917
- static ngx_int_t
914
+ static void
918
915
ngx_http_lua_pipe_close_helper (ngx_http_lua_pipe_ctx_t * pipe_ctx ,
919
- ngx_event_t * ev , int forced )
916
+ ngx_event_t * ev )
920
917
{
921
- if (ev -> handler != ngx_http_lua_pipe_dummy_event_handler && !forced ) {
922
- ngx_log_debug3 (NGX_LOG_DEBUG_HTTP , ngx_cycle -> log , 0 ,
923
- "lua pipe cannot close fd:%d without "
924
- "forced pipe:%p ev:%p" , pipe_ctx -> c -> fd , pipe_ctx , ev );
925
- return NGX_ERROR ;
918
+ if (ev -> handler != ngx_http_lua_pipe_dummy_event_handler ) {
919
+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , ngx_cycle -> log , 0 ,
920
+ "lua pipe abort blocking operation pipe_ctx:%p ev:%p" ,
921
+ pipe_ctx , ev );
922
+
923
+ pipe_ctx -> err_type = PIPE_ERR_ABORTED ;
924
+ ngx_post_event (ev , & ngx_posted_events );
925
+ return ;
926
926
}
927
927
928
928
ngx_close_connection (pipe_ctx -> c );
929
929
pipe_ctx -> c = NULL ;
930
-
931
- return NGX_OK ;
932
930
}
933
931
934
932
935
- static ngx_int_t
936
- ngx_http_lua_pipe_close_stdin (ngx_http_lua_pipe_t * pipe , int forced )
933
+ static void
934
+ ngx_http_lua_pipe_close_stdin (ngx_http_lua_pipe_t * pipe )
937
935
{
938
936
ngx_event_t * wev ;
939
937
@@ -949,15 +947,13 @@ ngx_http_lua_pipe_close_stdin(ngx_http_lua_pipe_t *pipe, int forced)
949
947
950
948
} else if (pipe -> stdin_ctx -> c != NULL ) {
951
949
wev = pipe -> stdin_ctx -> c -> write ;
952
- return ngx_http_lua_pipe_close_helper (pipe -> stdin_ctx , wev , forced );
950
+ ngx_http_lua_pipe_close_helper (pipe -> stdin_ctx , wev );
953
951
}
954
-
955
- return NGX_OK ;
956
952
}
957
953
958
954
959
- static ngx_int_t
960
- ngx_http_lua_pipe_close_stdout (ngx_http_lua_pipe_t * pipe , int forced )
955
+ static void
956
+ ngx_http_lua_pipe_close_stdout (ngx_http_lua_pipe_t * pipe )
961
957
{
962
958
ngx_event_t * rev ;
963
959
@@ -973,15 +969,13 @@ ngx_http_lua_pipe_close_stdout(ngx_http_lua_pipe_t *pipe, int forced)
973
969
974
970
} else if (pipe -> stdout_ctx -> c != NULL ) {
975
971
rev = pipe -> stdout_ctx -> c -> read ;
976
- return ngx_http_lua_pipe_close_helper (pipe -> stdout_ctx , rev , forced );
972
+ ngx_http_lua_pipe_close_helper (pipe -> stdout_ctx , rev );
977
973
}
978
-
979
- return NGX_OK ;
980
974
}
981
975
982
976
983
- static ngx_int_t
984
- ngx_http_lua_pipe_close_stderr (ngx_http_lua_pipe_t * pipe , int forced )
977
+ static void
978
+ ngx_http_lua_pipe_close_stderr (ngx_http_lua_pipe_t * pipe )
985
979
{
986
980
ngx_event_t * rev ;
987
981
@@ -997,18 +991,15 @@ ngx_http_lua_pipe_close_stderr(ngx_http_lua_pipe_t *pipe, int forced)
997
991
998
992
} else if (pipe -> stderr_ctx -> c != NULL ) {
999
993
rev = pipe -> stderr_ctx -> c -> read ;
1000
- return ngx_http_lua_pipe_close_helper (pipe -> stderr_ctx , rev , forced );
994
+ ngx_http_lua_pipe_close_helper (pipe -> stderr_ctx , rev );
1001
995
}
1002
-
1003
- return NGX_OK ;
1004
996
}
1005
997
1006
998
1007
999
int
1008
1000
ngx_http_lua_ffi_pipe_proc_shutdown_stdin (ngx_http_lua_ffi_pipe_proc_t * proc ,
1009
1001
u_char * errbuf , size_t * errbuf_size )
1010
1002
{
1011
- ngx_int_t rc ;
1012
1003
ngx_http_lua_pipe_t * pipe ;
1013
1004
1014
1005
pipe = proc -> pipe ;
@@ -1017,12 +1008,7 @@ ngx_http_lua_ffi_pipe_proc_shutdown_stdin(ngx_http_lua_ffi_pipe_proc_t *proc,
1017
1008
return NGX_ERROR ;
1018
1009
}
1019
1010
1020
- rc = ngx_http_lua_pipe_close_stdin (pipe , 0 );
1021
- if (rc != NGX_OK ) {
1022
- * errbuf_size = ngx_snprintf (errbuf , * errbuf_size , "pipe busy writing" )
1023
- - errbuf ;
1024
- return NGX_ERROR ;
1025
- }
1011
+ ngx_http_lua_pipe_close_stdin (pipe );
1026
1012
1027
1013
return NGX_OK ;
1028
1014
}
@@ -1032,7 +1018,6 @@ int
1032
1018
ngx_http_lua_ffi_pipe_proc_shutdown_stdout (ngx_http_lua_ffi_pipe_proc_t * proc ,
1033
1019
u_char * errbuf , size_t * errbuf_size )
1034
1020
{
1035
- ngx_int_t rc ;
1036
1021
ngx_http_lua_pipe_t * pipe ;
1037
1022
1038
1023
pipe = proc -> pipe ;
@@ -1041,12 +1026,7 @@ ngx_http_lua_ffi_pipe_proc_shutdown_stdout(ngx_http_lua_ffi_pipe_proc_t *proc,
1041
1026
return NGX_ERROR ;
1042
1027
}
1043
1028
1044
- rc = ngx_http_lua_pipe_close_stdout (pipe , 0 );
1045
- if (rc != NGX_OK ) {
1046
- * errbuf_size = ngx_snprintf (errbuf , * errbuf_size , "pipe busy reading" )
1047
- - errbuf ;
1048
- return NGX_ERROR ;
1049
- }
1029
+ ngx_http_lua_pipe_close_stdout (pipe );
1050
1030
1051
1031
return NGX_OK ;
1052
1032
}
@@ -1071,24 +1051,20 @@ ngx_http_lua_ffi_pipe_proc_shutdown_stderr(ngx_http_lua_ffi_pipe_proc_t *proc,
1071
1051
return NGX_ERROR ;
1072
1052
}
1073
1053
1074
- if (ngx_http_lua_pipe_close_stderr (pipe , 0 ) != NGX_OK ) {
1075
- * errbuf_size = ngx_snprintf (errbuf , * errbuf_size , "pipe busy reading" )
1076
- - errbuf ;
1077
- return NGX_ERROR ;
1078
- }
1054
+ ngx_http_lua_pipe_close_stderr (pipe );
1079
1055
1080
1056
return NGX_OK ;
1081
1057
}
1082
1058
1083
1059
1084
1060
static void
1085
- ngx_http_lua_pipe_proc_finalize (ngx_http_lua_ffi_pipe_proc_t * proc , int forced )
1061
+ ngx_http_lua_pipe_proc_finalize (ngx_http_lua_ffi_pipe_proc_t * proc )
1086
1062
{
1087
1063
ngx_http_lua_pipe_t * pipe ;
1088
1064
1089
- ngx_log_debug3 (NGX_LOG_DEBUG_HTTP , ngx_cycle -> log , 0 ,
1090
- "lua pipe finalize process:%p pid:%P forced:%d" , proc ,
1091
- proc -> _pid , forced );
1065
+ ngx_log_debug2 (NGX_LOG_DEBUG_HTTP , ngx_cycle -> log , 0 ,
1066
+ "lua pipe finalize process:%p pid:%P" ,
1067
+ proc , proc -> _pid );
1092
1068
pipe = proc -> pipe ;
1093
1069
1094
1070
if (pipe -> node ) {
@@ -1098,11 +1074,11 @@ ngx_http_lua_pipe_proc_finalize(ngx_http_lua_ffi_pipe_proc_t *proc, int forced)
1098
1074
1099
1075
pipe -> dead = 1 ;
1100
1076
1101
- ngx_http_lua_pipe_close_stdin (pipe , forced );
1102
- ngx_http_lua_pipe_close_stdout (pipe , forced );
1077
+ ngx_http_lua_pipe_close_stdin (pipe );
1078
+ ngx_http_lua_pipe_close_stdout (pipe );
1103
1079
1104
1080
if (!pipe -> merge_stderr ) {
1105
- ngx_http_lua_pipe_close_stderr (pipe , forced );
1081
+ ngx_http_lua_pipe_close_stderr (pipe );
1106
1082
}
1107
1083
1108
1084
pipe -> closed = 1 ;
@@ -1135,7 +1111,7 @@ ngx_http_lua_ffi_pipe_proc_destroy(ngx_http_lua_ffi_pipe_proc_t *proc)
1135
1111
}
1136
1112
}
1137
1113
1138
- ngx_http_lua_pipe_proc_finalize (proc , 1 );
1114
+ ngx_http_lua_pipe_proc_finalize (proc );
1139
1115
ngx_destroy_pool (pipe -> pool );
1140
1116
proc -> pipe = NULL ;
1141
1117
}
@@ -1205,6 +1181,10 @@ ngx_http_lua_pipe_put_error(ngx_http_lua_pipe_ctx_t *pipe_ctx, u_char *errbuf,
1205
1181
- errbuf ;
1206
1182
break ;
1207
1183
1184
+ case PIPE_ERR_ABORTED :
1185
+ * errbuf_size = ngx_snprintf (errbuf , * errbuf_size , "aborted" ) - errbuf ;
1186
+ break ;
1187
+
1208
1188
default :
1209
1189
ngx_log_error (NGX_LOG_ERR , ngx_cycle -> log , 0 ,
1210
1190
"unexpected err type: %d" , pipe_ctx -> err_type );
@@ -2005,7 +1985,7 @@ ngx_http_lua_ffi_pipe_proc_wait(ngx_http_request_t *r,
2005
1985
* reason = REASON_UNKNOWN ;
2006
1986
}
2007
1987
2008
- ngx_http_lua_pipe_proc_finalize (proc , 0 );
1988
+ ngx_http_lua_pipe_proc_finalize (proc );
2009
1989
2010
1990
if (* status == 0 ) {
2011
1991
return NGX_OK ;
@@ -2096,6 +2076,12 @@ ngx_http_lua_pipe_read_retval_helper(ngx_http_lua_ffi_pipe_proc_t *proc,
2096
2076
return 0 ;
2097
2077
}
2098
2078
2079
+ if (pipe_ctx -> err_type == PIPE_ERR_ABORTED ) {
2080
+ ngx_close_connection (pipe_ctx -> c );
2081
+ pipe_ctx -> c = NULL ;
2082
+ return 0 ;
2083
+ }
2084
+
2099
2085
rc = ngx_http_lua_pipe_read (pipe , pipe_ctx );
2100
2086
if (rc != NGX_AGAIN ) {
2101
2087
return 0 ;
@@ -2147,6 +2133,12 @@ ngx_http_lua_pipe_write_retval(ngx_http_lua_ffi_pipe_proc_t *proc,
2147
2133
return 0 ;
2148
2134
}
2149
2135
2136
+ if (pipe_ctx -> err_type == PIPE_ERR_ABORTED ) {
2137
+ ngx_close_connection (pipe_ctx -> c );
2138
+ pipe_ctx -> c = NULL ;
2139
+ return 0 ;
2140
+ }
2141
+
2150
2142
rc = ngx_http_lua_pipe_write (pipe , pipe_ctx );
2151
2143
if (rc != NGX_AGAIN ) {
2152
2144
return 0 ;
@@ -2192,7 +2184,7 @@ ngx_http_lua_pipe_wait_retval(ngx_http_lua_ffi_pipe_proc_t *proc, lua_State *L)
2192
2184
return 2 ;
2193
2185
}
2194
2186
2195
- ngx_http_lua_pipe_proc_finalize (pipe_node -> proc , 0 );
2187
+ ngx_http_lua_pipe_proc_finalize (pipe_node -> proc );
2196
2188
2197
2189
if (pipe_node -> status == 0 ) {
2198
2190
lua_pushboolean (L , 1 );
0 commit comments