Mercurial > hg > nginx
annotate auto/os/freebsd @ 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 | ec2e6893caaa |
children |
rev | line source |
---|---|
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
1 |
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
2 # Copyright (C) Igor Sysoev |
4412 | 3 # Copyright (C) Nginx, Inc. |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
376
diff
changeset
|
4 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
5 |
509 | 6 have=NGX_FREEBSD . auto/have_headers |
455 | 7 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 CORE_INCS="$UNIX_INCS" |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 CORE_DEPS="$UNIX_DEPS $FREEBSD_DEPS" |
238
674f85a4d00f
nginx-0.0.1-2004-01-23-12:26:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
215
diff
changeset
|
10 CORE_SRCS="$UNIX_SRCS $FREEBSD_SRCS" |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
455 | 12 ngx_spacer=' |
13 ' | |
283
8f65fee68270
nginx-0.0.2-2004-03-10-20:55:19 import
Igor Sysoev <igor@sysoev.ru>
parents:
272
diff
changeset
|
14 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
455 | 16 # __FreeBSD_version and sysctl kern.osreldate are the best ways |
17 # to determine whether some capability exists and is safe to use. | |
686 | 18 # __FreeBSD_version is used for the testing of the build environment. |
455 | 19 # sysctl kern.osreldate is used for the testing of the kernel capabilities. |
260
5dacbb4daaf6
nginx-0.0.2-2004-02-17-20:53:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
253
diff
changeset
|
20 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
21 version=`grep "#define __FreeBSD_version" /usr/include/osreldate.h \ |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 | sed -e 's/^.* \(.*\)$/\1/'` |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
455 | 24 osreldate=`/sbin/sysctl -n kern.osreldate` |
25 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
26 |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
27 # setproctitle() in libutil |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
28 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
29 if [ \( $version -ge 500000 -a $version -lt 500012 \) \ |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
30 -o $version -lt 410002 ] |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
31 then |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
32 echo " + setproctitle() in libutil" |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
33 |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
34 CORE_LIBS="$CORE_LIBS -lutil" |
509 | 35 NGX_SETPROCTITLE_LIB="-lutil" |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
36 fi |
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
37 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
38 # sendfile |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
39 |
455 | 40 if [ $osreldate -gt 300007 ]; then |
563 | 41 echo " + sendfile() found" |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
42 |
469 | 43 have=NGX_HAVE_SENDFILE . auto/have |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
44 CORE_SRCS="$CORE_SRCS $FREEBSD_SENDFILE_SRCS" |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
45 fi |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
7985
ec2e6893caaa
Simplified sendfile(SF_NODISKIO) usage.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6125
diff
changeset
|
47 if [ $osreldate -gt 1100093 ]; then |
ec2e6893caaa
Simplified sendfile(SF_NODISKIO) usage.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6125
diff
changeset
|
48 echo " + sendfile()'s SF_NODISKIO found" |
3065 | 49 |
7985
ec2e6893caaa
Simplified sendfile(SF_NODISKIO) usage.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6125
diff
changeset
|
50 have=NGX_HAVE_SENDFILE_NODISKIO . auto/have |
3065 | 51 fi |
52 | |
3909
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
53 # POSIX semaphores |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
54 # http://www.freebsd.org/cgi/query-pr.cgi?pr=kern/127545 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
55 |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
56 if [ $osreldate -ge 701106 ]; then |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
57 echo " + POSIX semaphores should work" |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
58 else |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
59 have=NGX_HAVE_POSIX_SEM . auto/nohave |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
60 fi |
0daede16d68b
use POSIX semaphores in shmtx instead of sched_yield()
Igor Sysoev <igor@sysoev.ru>
parents:
3065
diff
changeset
|
61 |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
62 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
63 # kqueue |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
64 |
455 | 65 if [ \( $osreldate -lt 500000 -a $osreldate -ge 410000 \) \ |
66 -o $osreldate -ge 500011 ] | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
67 then |
563 | 68 echo " + kqueue found" |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
69 |
469 | 70 have=NGX_HAVE_KQUEUE . auto/have |
71 have=NGX_HAVE_CLEAR_EVENT . auto/have | |
298
4a3f18406832
nginx-0.0.3-2004-03-30-10:27:36 import
Igor Sysoev <igor@sysoev.ru>
parents:
291
diff
changeset
|
72 EVENT_MODULES="$EVENT_MODULES $KQUEUE_MODULE" |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
73 CORE_SRCS="$CORE_SRCS $KQUEUE_SRCS" |
248
e885208c518b
nginx-0.0.2-2004-02-03-00:19:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
238
diff
changeset
|
74 EVENT_FOUND=YES |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
75 fi |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
76 |
489 | 77 |
455 | 78 NGX_KQUEUE_CHECKED=YES |
79 | |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
80 |
5982
f3f25ad09dee
Configure: typo fixed.
Sergey Kandaurov <pluknet@nginx.com>
parents:
5981
diff
changeset
|
81 # kqueue's NOTE_LOWAT |
195
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
82 |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
83 if [ \( $version -lt 500000 -a $version -ge 430000 \) \ |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
84 -o $version -ge 500018 ] |
8dee38ea9117
nginx-0.0.1-2003-11-25-23:44:56 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
85 then |
563 | 86 echo " + kqueue's NOTE_LOWAT found" |
469 | 87 have=NGX_HAVE_LOWAT_EVENT . auto/have |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
88 fi |
267
83205e0b5522
nginx-0.0.2-2004-02-24-20:31:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
261
diff
changeset
|
89 |
563 | 90 # kqueue's EVFILT_TIMER |
91 | |
92 if [ \( $version -lt 500000 -a $version -ge 440001 \) \ | |
93 -o $version -ge 500023 ] | |
94 then | |
95 echo " + kqueue's EVFILT_TIMER found" | |
96 have=NGX_HAVE_TIMER_EVENT . auto/have | |
97 fi | |
98 | |
376
d0451e402e27
nginx-0.0.7-2004-07-05-10:55:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
355
diff
changeset
|
99 |
4549
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
100 # cpuset_setaffinity() |
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
101 |
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
102 if [ $version -ge 701000 ]; then |
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
103 echo " + cpuset_setaffinity() found" |
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
104 have=NGX_HAVE_CPUSET_SETAFFINITY . auto/have |
f31162fefe01
worker_cpu_affinity: cleaned up Linux implementation, added FreeBSD support.
Ruslan Ermilov <ru@nginx.com>
parents:
4412
diff
changeset
|
105 fi |