annotate auto/cc/clang @ 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 ceab908790c4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4762
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
1
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
2 # Copyright (C) Nginx, Inc.
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
3
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
4
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
5 # clang
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
6
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
7
7161
325b3042edd6 Configure: fixed clang detection on MINIX.
Maxim Dounin <mdounin@mdounin.ru>
parents: 6603
diff changeset
8 NGX_CLANG_VER=`$CC -v 2>&1 | grep 'version' 2>&1 \
7273
ceab908790c4 Configure: fixed clang version detection (closes #1539).
Ruslan Ermilov <ru@nginx.com>
parents: 7161
diff changeset
9 | sed -n -e 's/^.*clang version \(.*\)/\1/p' \
ceab908790c4 Configure: fixed clang version detection (closes #1539).
Ruslan Ermilov <ru@nginx.com>
parents: 7161
diff changeset
10 -e 's/^.*LLVM version \(.*\)/\1/p'`
4762
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
11
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
12 echo " + clang version: $NGX_CLANG_VER"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
13
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
14 have=NGX_COMPILER value="\"clang $NGX_CLANG_VER\"" . auto/define
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
15
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
16
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
17 CC_TEST_FLAGS="-pipe"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
18
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
19
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
20 # optimizations
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
21
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
22 #NGX_CLANG_OPT="-O2"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
23 #NGX_CLANG_OPT="-Oz"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
24 NGX_CLANG_OPT="-O"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
25
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
26 case $CPU in
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
27 pentium)
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
28 # optimize for Pentium
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
29 CPU_OPT="-march=pentium"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
30 NGX_CPU_CACHE_LINE=32
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
31 ;;
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
32
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
33 pentiumpro | pentium3)
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
34 # optimize for Pentium Pro, Pentium II and Pentium III
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
35 CPU_OPT="-march=pentiumpro"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
36 NGX_CPU_CACHE_LINE=32
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
37 ;;
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
38
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
39 pentium4)
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
40 # optimize for Pentium 4
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
41 CPU_OPT="-march=pentium4"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
42 NGX_CPU_CACHE_LINE=128
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
43 ;;
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
44
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
45 athlon)
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
46 # optimize for Athlon
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
47 CPU_OPT="-march=athlon"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
48 NGX_CPU_CACHE_LINE=64
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
49 ;;
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
50
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
51 opteron)
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
52 # optimize for Opteron
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
53 CPU_OPT="-march=opteron"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
54 NGX_CPU_CACHE_LINE=64
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
55 ;;
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
56
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
57 esac
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
58
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
59 CC_AUX_FLAGS="$CC_AUX_FLAGS $CPU_OPT"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
60
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
61
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
62 CFLAGS="$CFLAGS -pipe $CPU_OPT"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
63
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
64 if [ ".$PCRE_OPT" = "." ]; then
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
65 PCRE_OPT="-O2 -pipe $CPU_OPT"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
66 else
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
67 PCRE_OPT="$PCRE_OPT -pipe"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
68 fi
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
69
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
70 if [ ".$ZLIB_OPT" = "." ]; then
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
71 ZLIB_OPT="-O2 -pipe $CPU_OPT"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
72 else
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
73 ZLIB_OPT="$ZLIB_OPT -pipe"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
74 fi
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
75
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
76
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
77 # warnings
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
78
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
79 CFLAGS="$CFLAGS $NGX_CLANG_OPT -Wall -Wextra -Wpointer-arith"
5459
fedf777c6b24 Configure: enable -Wconditional-uninitialized with clang.
Ruslan Ermilov <ru@nginx.com>
parents: 5187
diff changeset
80 CFLAGS="$CFLAGS -Wconditional-uninitialized"
4762
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
81 #CFLAGS="$CFLAGS -Wmissing-prototypes"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
82
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
83 # we have a lot of unused function arguments
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
84 CFLAGS="$CFLAGS -Wno-unused-parameter"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
85
5714
80bd391c90d1 Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5539
diff changeset
86 # deprecated system OpenSSL library on OS X
80bd391c90d1 Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5539
diff changeset
87 if [ "$NGX_SYSTEM" = "Darwin" ]; then
80bd391c90d1 Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5539
diff changeset
88 CFLAGS="$CFLAGS -Wno-deprecated-declarations"
80bd391c90d1 Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5539
diff changeset
89 fi
80bd391c90d1 Configure: added -Wno-deprecated-declarations on OS X.
Maxim Dounin <mdounin@mdounin.ru>
parents: 5539
diff changeset
90
4762
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
91 # stop on warning
5539
c86dd32573c0 Configure: enabled -Werror for clang.
Ruslan Ermilov <ru@nginx.com>
parents: 5459
diff changeset
92 CFLAGS="$CFLAGS -Werror"
4762
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
93
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
94 # debug
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
95 CFLAGS="$CFLAGS -g"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
96
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
97 if [ ".$CPP" = "." ]; then
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
98 CPP="$CC -E"
182aee3b1bf5 Added the Clang compiler support.
Ruslan Ermilov <ru@nginx.com>
parents:
diff changeset
99 fi