Mercurial > hg > nginx
annotate auto/cc/gcc @ 9203:0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
When a request was terminated due to an error via ngx_http_terminate_request()
while an AIO operation was running in a subrequest, various issues were
observed. This happened because ngx_http_request_finalizer() was only set
in the subrequest where ngx_http_terminate_request() was called, but not
in the subrequest where the AIO operation was running. After completion
of the AIO operation normal processing of the subrequest was resumed, leading
to issues.
In particular, in case of the upstream module, termination of the request
called upstream cleanup, which closed the upstream connection. Attempts to
further work with the upstream connection after AIO operation completion
resulted in segfaults in ngx_ssl_recv(), "readv() failed (9: Bad file
descriptor) while reading upstream" errors, or socket leaks.
In ticket #2555, issues were observed with the following configuration
with cache background update (with thread writing instrumented to
introduce a delay, when a client closes the connection during an update):
location = /background-and-aio-write {
proxy_pass ...
proxy_cache one;
proxy_cache_valid 200 1s;
proxy_cache_background_update on;
proxy_cache_use_stale updating;
aio threads;
aio_write on;
limit_rate 1000;
}
Similarly, the same issue can be seen with SSI, and can be caused by
errors in subrequests, such as in the following configuration
(where "/proxy" uses AIO, and "/sleep" returns 444 after some delay,
causing request termination):
location = /ssi-active-boom {
ssi on;
ssi_types *;
return 200 '
<!--#include virtual="/proxy" -->
<!--#include virtual="/sleep" -->
';
limit_rate 1000;
}
Or the same with both AIO operation and the error in non-active subrequests
(which needs slightly different handling, see below):
location = /ssi-non-active-boom {
ssi on;
ssi_types *;
return 200 '
<!--#include virtual="/static" -->
<!--#include virtual="/proxy" -->
<!--#include virtual="/sleep" -->
';
limit_rate 1000;
}
Similarly, issues can be observed with just static files. However,
with static files potential impact is limited due to timeout safeguards
in ngx_http_writer(), and the fact that c->error is set during request
termination.
In a simple configuration with an AIO operation in the active subrequest,
such as in the following configuration, the connection is closed right
after completion of the AIO operation anyway, since ngx_http_writer()
tries to write to the connection and fails due to c->error set:
location = /ssi-active-static-boom {
ssi on;
ssi_types *;
return 200 '
<!--#include virtual="/static-aio" -->
<!--#include virtual="/sleep" -->
';
limit_rate 1000;
}
In the following configuration, with an AIO operation in a non-active
subrequest, the connection is closed only after send_timeout expires:
location = /ssi-non-active-static-boom {
ssi on;
ssi_types *;
return 200 '
<!--#include virtual="/static" -->
<!--#include virtual="/static-aio" -->
<!--#include virtual="/sleep" -->
';
limit_rate 1000;
}
Fix is to introduce r->main->terminated flag, which is to be checked
by AIO event handlers when the r->main->blocked counter is decremented.
When the flag is set, handlers are expected to wake up the connection
instead of the subrequest (which might be already cleaned up).
Additionally, now ngx_http_request_finalizer() is always set in the
active subrequest, so waking up the connection properly finalizes the
request even if termination happened in a non-active subrequest.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 30 Jan 2024 03:20:05 +0300 |
parents | 9eefb38f0005 |
children |
rev | line source |
---|---|
455 | 1 |
2 # Copyright (C) Igor Sysoev | |
4412 | 3 # Copyright (C) Nginx, Inc. |
455 | 4 |
5 | |
501 | 6 # gcc 2.7.2.3, 2.8.1, 2.95.4, egcs-1.1.2 |
497 | 7 # 3.0.4, 3.1.1, 3.2.3, 3.3.2, 3.3.3, 3.3.4, 3.4.0, 3.4.2 |
521 | 8 # 4.0.0, 4.0.1, 4.1.0 |
501 | 9 |
10 | |
11 NGX_GCC_VER=`$CC -v 2>&1 | grep 'gcc version' 2>&1 \ | |
12 | sed -e 's/^.* version \(.*\)/\1/'` | |
13 | |
14 echo " + gcc version: $NGX_GCC_VER" | |
455 | 15 |
557 | 16 have=NGX_COMPILER value="\"gcc $NGX_GCC_VER\"" . auto/define |
17 | |
455 | 18 |
19 # Solaris 7's /usr/ccs/bin/as does not support "-pipe" | |
20 | |
21 CC_TEST_FLAGS="-pipe" | |
22 | |
577 | 23 ngx_feature="gcc -pipe switch" |
455 | 24 ngx_feature_name= |
25 ngx_feature_run=no | |
26 ngx_feature_incs= | |
875
7af8276b1c2f
test PCRE in FreeBSD, Linux, and NetBSD
Igor Sysoev <igor@sysoev.ru>
parents:
743
diff
changeset
|
27 ngx_feature_path= |
455 | 28 ngx_feature_libs= |
29 ngx_feature_test= | |
30 . auto/feature | |
31 | |
32 CC_TEST_FLAGS= | |
33 | |
34 if [ $ngx_found = yes ]; then | |
35 PIPE="-pipe" | |
36 fi | |
37 | |
561 | 38 |
581 | 39 case "$NGX_MACHINE" in |
561 | 40 |
743 | 41 sun4u | sun4v | sparc | sparc64 ) |
563 | 42 # "-mcpu=v9" enables the "casa" assembler instruction |
561 | 43 CFLAGS="$CFLAGS -mcpu=v9" |
44 ;; | |
45 | |
46 esac | |
47 | |
48 | |
455 | 49 # optimizations |
50 | |
487 | 51 #NGX_GCC_OPT="-O2" |
52 #NGX_GCC_OPT="-Os" | |
53 NGX_GCC_OPT="-O" | |
54 | |
55 #CFLAGS="$CFLAGS -fomit-frame-pointer" | |
455 | 56 |
57 case $CPU in | |
58 pentium) | |
59 # optimize for Pentium and Athlon | |
60 CPU_OPT="-march=pentium" | |
589 | 61 NGX_CPU_CACHE_LINE=32 |
455 | 62 ;; |
63 | |
561 | 64 pentiumpro | pentium3) |
455 | 65 # optimize for Pentium Pro, Pentium II and Pentium III |
66 CPU_OPT="-march=pentiumpro" | |
589 | 67 NGX_CPU_CACHE_LINE=32 |
455 | 68 ;; |
69 | |
70 pentium4) | |
71 # optimize for Pentium 4, gcc 3.x | |
72 CPU_OPT="-march=pentium4" | |
589 | 73 NGX_CPU_CACHE_LINE=128 |
455 | 74 ;; |
75 | |
521 | 76 athlon) |
77 # optimize for Athlon, gcc 3.x | |
78 CPU_OPT="-march=athlon" | |
589 | 79 NGX_CPU_CACHE_LINE=64 |
521 | 80 ;; |
81 | |
509 | 82 opteron) |
83 # optimize for Opteron, gcc 3.x | |
84 CPU_OPT="-march=opteron" | |
589 | 85 NGX_CPU_CACHE_LINE=64 |
509 | 86 ;; |
87 | |
581 | 88 sparc32) |
89 # build 32-bit UltraSparc binary | |
90 CPU_OPT="-m32" | |
91 CORE_LINK="$CORE_LINK -m32" | |
589 | 92 NGX_CPU_CACHE_LINE=64 |
581 | 93 ;; |
94 | |
455 | 95 sparc64) |
96 # build 64-bit UltraSparc binary | |
97 CPU_OPT="-m64" | |
98 CORE_LINK="$CORE_LINK -m64" | |
589 | 99 NGX_CPU_CACHE_LINE=64 |
455 | 100 ;; |
101 | |
613 | 102 ppc64) |
103 # build 64-bit PowerPC binary | |
104 CPU_OPT="-m64" | |
105 CPU_OPT="$CPU_OPT -falign-functions=32 -falign-labels=32" | |
106 CPU_OPT="$CPU_OPT -falign-loops=32 -falign-jumps=32" | |
107 CORE_LINK="$CORE_LINK -m64" | |
108 NGX_CPU_CACHE_LINE=128 | |
109 ;; | |
110 | |
455 | 111 esac |
112 | |
3362
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
2751
diff
changeset
|
113 CC_AUX_FLAGS="$CC_AUX_FLAGS $CPU_OPT" |
455 | 114 |
501 | 115 case "$NGX_GCC_VER" in |
116 2.7*) | |
117 # batch build | |
118 CPU_OPT= | |
119 ;; | |
120 esac | |
455 | 121 |
122 | |
123 CFLAGS="$CFLAGS $PIPE $CPU_OPT" | |
124 | |
125 if [ ".$PCRE_OPT" = "." ]; then | |
126 PCRE_OPT="-O2 -fomit-frame-pointer $PIPE $CPU_OPT" | |
127 else | |
128 PCRE_OPT="$PCRE_OPT $PIPE" | |
129 fi | |
130 | |
131 if [ ".$ZLIB_OPT" = "." ]; then | |
132 ZLIB_OPT="-O2 -fomit-frame-pointer $PIPE $CPU_OPT" | |
133 else | |
134 ZLIB_OPT="$ZLIB_OPT $PIPE" | |
135 fi | |
136 | |
137 | |
138 # warnings | |
139 | |
487 | 140 # -W requires at least -O |
1010 | 141 CFLAGS="$CFLAGS ${NGX_GCC_OPT:--O} -W" |
487 | 142 |
455 | 143 CFLAGS="$CFLAGS -Wall -Wpointer-arith" |
577 | 144 #CFLAGS="$CFLAGS -Wconversion" |
455 | 145 #CFLAGS="$CFLAGS -Winline" |
4760
d87b45d4a8a0
Added a commented out -Wmissing-prototypes to CFLAGS.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
146 #CFLAGS="$CFLAGS -Wmissing-prototypes" |
455 | 147 |
6583
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
148 case "$NGX_GCC_VER" in |
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
149 2.*) |
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
150 # we have a lot of the unused function arguments |
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
151 CFLAGS="$CFLAGS -Wno-unused" |
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
152 ;; |
501 | 153 |
6583
ade7d0335d77
Configure: revised GCC version processing.
Sergey Kandaurov <pluknet@nginx.com>
parents:
6178
diff
changeset
|
154 *) |
501 | 155 # we have a lot of the unused function arguments |
156 CFLAGS="$CFLAGS -Wno-unused-parameter" | |
2751 | 157 # 4.2.1 shows the warning in wrong places |
501 | 158 #CFLAGS="$CFLAGS -Wunreachable-code" |
5714
80bd391c90d1
Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4767
diff
changeset
|
159 |
80bd391c90d1
Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4767
diff
changeset
|
160 # deprecated system OpenSSL library on OS X |
80bd391c90d1
Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4767
diff
changeset
|
161 if [ "$NGX_SYSTEM" = "Darwin" ]; then |
80bd391c90d1
Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4767
diff
changeset
|
162 CFLAGS="$CFLAGS -Wno-deprecated-declarations" |
80bd391c90d1
Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents:
4767
diff
changeset
|
163 fi |
501 | 164 ;; |
165 esac | |
166 | |
455 | 167 |
168 # stop on warning | |
169 CFLAGS="$CFLAGS -Werror" | |
170 | |
171 # debug | |
172 CFLAGS="$CFLAGS -g" | |
173 | |
174 # DragonFly's gcc3 generates DWARF | |
175 #CFLAGS="$CFLAGS -g -gstabs" | |
176 | |
177 if [ ".$CPP" = "." ]; then | |
178 CPP="$CC -E" | |
179 fi |