Mercurial > hg > nginx
annotate auto/cc/sunc @ 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 | d8e8ced78e77 |
children |
rev | line source |
---|---|
561 | 1 |
2 # Copyright (C) Igor Sysoev | |
4412 | 3 # Copyright (C) Nginx, Inc. |
561 | 4 |
5 | |
1309 | 6 # Sun C 5.7 Patch 117837-04 2005/05/11 Sun Studio 10 |
7 # Sun C 5.8 2005/10/13 Sun Studio 11 | |
8 # Sun C 5.9 SunOS_i386 2007/05/03 Sun Studio 12 | |
9 # Sun C 5.9 SunOS_sparc 2007/05/03 | |
4004
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
10 # Sun C 5.10 SunOS_i386 2009/06/03 Sun Studio 12.1 |
7000
d8e8ced78e77
Configure: recent Sun C versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6624
diff
changeset
|
11 # Sun C 5.11 SunOS_i386 2010/08/13 Oracle Solaris Studio 12.2 |
d8e8ced78e77
Configure: recent Sun C versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6624
diff
changeset
|
12 # Sun C 5.12 SunOS_i386 2011/11/16 Oracle Solaris Studio 12.3 |
d8e8ced78e77
Configure: recent Sun C versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6624
diff
changeset
|
13 # Sun C 5.13 SunOS_i386 2014/10/20 Oracle Solaris Studio 12.4 |
d8e8ced78e77
Configure: recent Sun C versions.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6624
diff
changeset
|
14 # Sun C 5.14 SunOS_i386 2016/05/31 Oracle Developer Studio 12.5 |
561 | 15 |
16 NGX_SUNC_VER=`$CC -V 2>&1 | grep 'Sun C' 2>&1 \ | |
702
67deba330372
auto/configure [ PAUSE ] hwcap bug
Igor Sysoev <igor@sysoev.ru>
parents:
697
diff
changeset
|
17 | sed -e 's/^.* Sun C \(.*\)/\1/'` |
561 | 18 |
19 echo " + Sun C version: $NGX_SUNC_VER" | |
20 | |
21 have=NGX_COMPILER value="\"Sun C $NGX_SUNC_VER\"" . auto/define | |
22 | |
23 | |
1309 | 24 cat << END > $NGX_AUTOTEST.c |
25 | |
6624
e3faa5fb7772
Configure: fix build with -Werror=old-style-definition.
Piotr Sikora <piotrsikora@google.com>
parents:
6603
diff
changeset
|
26 int main(void) { |
e3faa5fb7772
Configure: fix build with -Werror=old-style-definition.
Piotr Sikora <piotrsikora@google.com>
parents:
6603
diff
changeset
|
27 printf("%d", __SUNPRO_C); |
e3faa5fb7772
Configure: fix build with -Werror=old-style-definition.
Piotr Sikora <piotrsikora@google.com>
parents:
6603
diff
changeset
|
28 return 0; |
e3faa5fb7772
Configure: fix build with -Werror=old-style-definition.
Piotr Sikora <piotrsikora@google.com>
parents:
6603
diff
changeset
|
29 } |
1309 | 30 |
31 END | |
32 | |
33 eval "$CC -o $NGX_AUTOTEST $NGX_AUTOTEST.c >> $NGX_ERR 2>&1" | |
34 | |
35 if [ -x $NGX_AUTOTEST ]; then | |
36 ngx_sunc_ver=`$NGX_AUTOTEST` | |
37 fi | |
38 | |
5309
434548349838
Configure: fixed autotest cleanup commands.
Sergey Kandaurov <pluknet@nginx.com>
parents:
4412
diff
changeset
|
39 rm -rf $NGX_AUTOTEST* |
1309 | 40 |
41 # 1424 == 0x590, Sun Studio 12 | |
42 | |
43 if [ "$ngx_sunc_ver" -ge 1424 ]; then | |
44 ngx_sparc32="-m32" | |
45 ngx_sparc64="-m64" | |
46 ngx_amd64="-m64" | |
47 | |
48 else | |
49 ngx_sparc32="-xarch=v8plus" | |
50 ngx_sparc64="-xarch=v9" | |
1343
d77866cf2cc4
fix building on amd64 by Sun Studio 11 and more early versions
Igor Sysoev <igor@sysoev.ru>
parents:
1324
diff
changeset
|
51 ngx_amd64="-xarch=amd64" |
1309 | 52 fi |
53 | |
744 | 54 case "$NGX_MACHINE" in |
561 | 55 |
744 | 56 i86pc) |
561 | 57 NGX_AUX=" src/os/unix/ngx_sunpro_x86.il" |
58 ;; | |
59 | |
744 | 60 sun4u | sun4v) |
561 | 61 NGX_AUX=" src/os/unix/ngx_sunpro_sparc64.il" |
62 ;; | |
63 | |
64 esac | |
65 | |
6383 | 66 MAIN_LINK= |
67 MODULE_LINK="-G" | |
68 | |
561 | 69 |
70 # optimizations | |
71 | |
4004
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
72 # 20736 == 0x5100, Sun Studio 12.1 |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
73 |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
74 if [ "$ngx_sunc_ver" -ge 20736 ]; then |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
75 ngx_fast="-fast" |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
76 |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
77 else |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
78 # older versions had problems with bit-fields |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
79 ngx_fast="-fast -xalias_level=any" |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
80 fi |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
81 |
1309 | 82 IPO=-xipo |
4004
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
83 CFLAGS="$CFLAGS $ngx_fast $IPO" |
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
84 CORE_LINK="$CORE_LINK $ngx_fast $IPO" |
561 | 85 |
86 | |
87 case $CPU in | |
88 pentium) | |
89 # optimize for Pentium and Athlon | |
90 CPU_OPT="-xchip=pentium" | |
91 ;; | |
92 | |
93 pentiumpro) | |
94 # optimize for Pentium Pro, Pentium II | |
95 CPU_OPT="-xchip=pentium_pro" | |
96 ;; | |
97 | |
98 pentium3) | |
99 # optimize for Pentium III | |
100 CPU_OPT="-xchip=pentium3" | |
101 #CPU_OPT="$CPU_OPT -xarch=sse" | |
102 CPU_OPT="$CPU_OPT -xcache=16/32/4:256/32/4" | |
103 ;; | |
104 | |
105 pentium4) | |
106 # optimize for Pentium 4 | |
107 CPU_OPT="-xchip=pentium4" | |
108 #CPU_OPT="$CPU_OPT -xarch=sse2" | |
109 CPU_OPT="$CPU_OPT -xcache=8/64/4:256/128/8" | |
110 ;; | |
111 | |
112 opteron) | |
113 # optimize for Opteron | |
114 CPU_OPT="-xchip=opteron" | |
115 #CPU_OPT="$CPU_OPT -xarch=sse2" | |
116 CPU_OPT="$CPU_OPT -xcache=64/64/2:1024/64/16" | |
117 ;; | |
118 | |
1308
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
119 sparc32) |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
120 # build 32-bit UltraSparc binary |
1309 | 121 CPU_OPT="$ngx_sparc32" |
122 CORE_LINK="$CORE_LINK $ngx_sparc32" | |
123 CC_AUX_FLAGS="$CC_AUX_FLAGS $ngx_sparc32" | |
1308
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
124 NGX_CPU_CACHE_LINE=64 |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
125 ;; |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
126 |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
127 sparc64) |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
128 # build 64-bit UltraSparc binary |
1309 | 129 CPU_OPT="$ngx_sparc64" |
130 CORE_LINK="$CORE_LINK $ngx_sparc64" | |
131 CC_AUX_FLAGS="$CC_AUX_FLAGS $ngx_sparc64" | |
1308
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
132 NGX_CPU_CACHE_LINE=64 |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
133 ;; |
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
1307
diff
changeset
|
134 |
561 | 135 amd64) |
136 # build 64-bit amd64 binary | |
1309 | 137 CPU_OPT="$ngx_amd64" |
138 CORE_LINK="$CORE_LINK $ngx_amd64" | |
1324
d01f9856e3a0
fix building on amd64 and add -xipo to the link stage
Igor Sysoev <igor@sysoev.ru>
parents:
1309
diff
changeset
|
139 CC_AUX_FLAGS="$CC_AUX_FLAGS $ngx_amd64" |
561 | 140 NGX_AUX=" src/os/unix/ngx_sunpro_amd64.il" |
1309 | 141 NGX_CPU_CACHE_LINE=64 |
561 | 142 ;; |
143 | |
144 esac | |
145 | |
146 | |
147 CFLAGS="$CFLAGS $CPU_OPT" | |
148 | |
149 | |
150 if [ ".$PCRE_OPT" = "." ]; then | |
4004
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
151 PCRE_OPT="$ngx_fast $IPO $CPU_OPT" |
561 | 152 fi |
153 | |
154 if [ ".$ZLIB_OPT" = "." ]; then | |
4004
84bd993b8cd3
Lower optimization level for Sun Studio before 12.1.
Maxim Dounin <mdounin@mdounin.ru>
parents:
2818
diff
changeset
|
155 ZLIB_OPT="$ngx_fast $IPO $CPU_OPT" |
561 | 156 fi |
157 | |
158 | |
159 # stop on warning | |
160 CFLAGS="$CFLAGS -errwarn=%all" | |
1375
8d7120543619
add debug info for Sun Studio
Igor Sysoev <igor@sysoev.ru>
parents:
1343
diff
changeset
|
161 |
8d7120543619
add debug info for Sun Studio
Igor Sysoev <igor@sysoev.ru>
parents:
1343
diff
changeset
|
162 # debug |
8d7120543619
add debug info for Sun Studio
Igor Sysoev <igor@sysoev.ru>
parents:
1343
diff
changeset
|
163 CFLAGS="$CFLAGS -g" |