Mercurial > hg > nginx
annotate src/http/ngx_http_copy_filter_module.c @ 9300:5be23505292b
SSI: fixed incorrect or duplicate stub output.
Following 3518:eb3aaf8bd2a9 (0.8.37), r->request_output is only set
if there are data in the first buffer sent in the subrequest. As a
result, following the change mentioned this flag cannot be used to
prevent duplicate ngx_http_ssi_stub_output() calls, since it is not
set if there was already some output, but the first buffer was empty.
Still, when there are multiple subrequests, even an empty subrequest
response might be delayed by the postpone filter, leading to a second
call of ngx_http_ssi_stub_output() during finalization from
ngx_http_writer() the subreqest buffers are released by the postpone
filter. Since r->request_output is not set after the first call, this
resulted in duplicate stub output.
Additionally, checking only the first buffer might be wrong in some
unusual cases. For example, the first buffer might be empty if
$r->flush() is called before printing any data in the embedded Perl
module.
Depending on the postpone_output value and corresponding sizes, this
issue can result in either duplicate or unexpected stub output, or
"zero size buf in writer" alerts.
Following 8124:f5515e727656 (1.23.4), it became slightly easier to
reproduce the issue, as empty static files and empty cache items now
result in a response with an empty buffer. Before the change, an empty
proxied response can be used to reproduce the issue.
Fix is check all buffers and set r->request_output if any non-empty
buffers are sent. This ensures that all unusual cases of non-empty
responses are covered, and also that r->request_output will be set
after the first stub output, preventing duplicate output.
Reported by Jan Gassen.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 04 Jul 2024 17:41:28 +0300 |
parents | 0de20f43db25 |
children |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
386
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
386
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
386
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
386
diff
changeset
|
6 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
33
b2e039840718
nginx-0.0.1-2002-12-19-20:49:51 import
Igor Sysoev <igor@sysoev.ru>
parents:
32
diff
changeset
|
8 #include <ngx_config.h> |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
9 #include <ngx_core.h> |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
10 #include <ngx_http.h> |
43
53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
11 |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
12 |
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
13 typedef struct { |
141
656d468f4ead
nginx-0.0.1-2003-10-08-19:32:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
14 ngx_bufs_t bufs; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
15 } ngx_http_copy_filter_conf_t; |
99
a059e1aa65d4
nginx-0.0.1-2003-06-02-19:24:30 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
16 |
43
53cd05892261
nginx-0.0.1-2002-12-27-19:22:50 import
Igor Sysoev <igor@sysoev.ru>
parents:
42
diff
changeset
|
17 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
18 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
19 static void ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
20 ngx_file_t *file); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
21 static void ngx_http_copy_aio_event_handler(ngx_event_t *ev); |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
22 #endif |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
23 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
24 static ngx_int_t ngx_http_copy_thread_handler(ngx_thread_task_t *task, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
25 ngx_file_t *file); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
26 static void ngx_http_copy_thread_event_handler(ngx_event_t *ev); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
27 #endif |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
28 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
29 static void *ngx_http_copy_filter_create_conf(ngx_conf_t *cf); |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
30 static char *ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, |
501 | 31 void *parent, void *child); |
681 | 32 static ngx_int_t ngx_http_copy_filter_init(ngx_conf_t *cf); |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
33 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
34 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
35 static ngx_command_t ngx_http_copy_filter_commands[] = { |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
36 |
501 | 37 { ngx_string("output_buffers"), |
38 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | |
39 ngx_conf_set_bufs_slot, | |
40 NGX_HTTP_LOC_CONF_OFFSET, | |
41 offsetof(ngx_http_copy_filter_conf_t, bufs), | |
42 NULL }, | |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
43 |
501 | 44 ngx_null_command |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
45 }; |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
46 |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
47 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
48 static ngx_http_module_t ngx_http_copy_filter_module_ctx = { |
509 | 49 NULL, /* preconfiguration */ |
681 | 50 ngx_http_copy_filter_init, /* postconfiguration */ |
177
4db54fdbcbe7
nginx-0.0.1-2003-11-10-20:17:31 import
Igor Sysoev <igor@sysoev.ru>
parents:
160
diff
changeset
|
51 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
52 NULL, /* create main configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
53 NULL, /* init main configuration */ |
69
e43f406e4525
nginx-0.0.1-2003-03-20-19:09:44 import
Igor Sysoev <igor@sysoev.ru>
parents:
67
diff
changeset
|
54 |
91
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
55 NULL, /* create server configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
56 NULL, /* merge server configuration */ |
637625a2acdb
nginx-0.0.1-2003-05-19-20:39:14 import
Igor Sysoev <igor@sysoev.ru>
parents:
90
diff
changeset
|
57 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
58 ngx_http_copy_filter_create_conf, /* create location configuration */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
59 ngx_http_copy_filter_merge_conf /* merge location configuration */ |
26
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
60 }; |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
61 |
53cb81681040
nginx-0.0.1-2002-12-15-09:25:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
24
diff
changeset
|
62 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
63 ngx_module_t ngx_http_copy_filter_module = { |
509 | 64 NGX_MODULE_V1, |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
65 &ngx_http_copy_filter_module_ctx, /* module context */ |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
66 ngx_http_copy_filter_commands, /* module directives */ |
96
a23d010f356d
nginx-0.0.1-2003-05-27-16:18:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
95
diff
changeset
|
67 NGX_HTTP_MODULE, /* module type */ |
541 | 68 NULL, /* init master */ |
681 | 69 NULL, /* init module */ |
541 | 70 NULL, /* init process */ |
71 NULL, /* init thread */ | |
72 NULL, /* exit thread */ | |
73 NULL, /* exit process */ | |
74 NULL, /* exit master */ | |
75 NGX_MODULE_V1_PADDING | |
40
d5d4f3bba6f0
nginx-0.0.1-2002-12-26-10:24:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
33
diff
changeset
|
76 }; |
8
708f8bb772ec
nginx-0.0.1-2002-09-02-18:48:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
7
diff
changeset
|
77 |
3
34a521b1a148
nginx-0.0.1-2002-08-20-18:48:28 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
78 |
4542
586969d972b9
Local variable "ngx_http_next_filter" renamed to "ngx_http_next_body_filter"
Ruslan Ermilov <ru@nginx.com>
parents:
4415
diff
changeset
|
79 static ngx_http_output_body_filter_pt ngx_http_next_body_filter; |
141
656d468f4ead
nginx-0.0.1-2003-10-08-19:32:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
80 |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
81 |
501 | 82 static ngx_int_t |
83 ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in) | |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
84 { |
583 | 85 ngx_int_t rc; |
9300
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
86 ngx_chain_t *cl; |
583 | 87 ngx_connection_t *c; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
88 ngx_output_chain_ctx_t *ctx; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
89 ngx_http_core_loc_conf_t *clcf; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
90 ngx_http_copy_filter_conf_t *conf; |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
91 |
583 | 92 c = r->connection; |
93 | |
94 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
3062
aa720192937b
use local variable and fix debug log message
Igor Sysoev <igor@sysoev.ru>
parents:
3053
diff
changeset
|
95 "http copy filter: \"%V?%V\"", &r->uri, &r->args); |
509 | 96 |
97 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); | |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
98 |
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
99 if (ctx == NULL) { |
501 | 100 ctx = ngx_pcalloc(r->pool, sizeof(ngx_output_chain_ctx_t)); |
101 if (ctx == NULL) { | |
102 return NGX_ERROR; | |
103 } | |
104 | |
105 ngx_http_set_ctx(r, ctx, ngx_http_copy_filter_module); | |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
106 |
3053 | 107 conf = ngx_http_get_module_loc_conf(r, ngx_http_copy_filter_module); |
108 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | |
109 | |
583 | 110 ctx->sendfile = c->sendfile; |
513 | 111 ctx->need_in_memory = r->main_filter_need_in_memory |
112 || r->filter_need_in_memory; | |
346
55e496a8ece3
nginx-0.0.3-2004-06-06-23:49:18 import
Igor Sysoev <igor@sysoev.ru>
parents:
343
diff
changeset
|
113 ctx->need_in_temp = r->filter_need_temporary; |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
114 |
3053 | 115 ctx->alignment = clcf->directio_alignment; |
116 | |
160
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
117 ctx->pool = r->pool; |
e7e094d34162
nginx-0.0.1-2003-10-27-11:53:49 import
Igor Sysoev <igor@sysoev.ru>
parents:
155
diff
changeset
|
118 ctx->bufs = conf->bufs; |
343
6bdf858bff8c
nginx-0.0.3-2004-05-28-19:49:23 import; rename ngx_hunk_t to ngx_buf_t
Igor Sysoev <igor@sysoev.ru>
parents:
334
diff
changeset
|
119 ctx->tag = (ngx_buf_tag_t) &ngx_http_copy_filter_module; |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
120 |
4542
586969d972b9
Local variable "ngx_http_next_filter" renamed to "ngx_http_next_body_filter"
Ruslan Ermilov <ru@nginx.com>
parents:
4415
diff
changeset
|
121 ctx->output_filter = (ngx_output_chain_filter_pt) |
586969d972b9
Local variable "ngx_http_next_filter" renamed to "ngx_http_next_body_filter"
Ruslan Ermilov <ru@nginx.com>
parents:
4415
diff
changeset
|
122 ngx_http_next_body_filter; |
294
5cfd65b8b0a7
nginx-0.0.3-2004-03-23-09:01:52 import
Igor Sysoev <igor@sysoev.ru>
parents:
177
diff
changeset
|
123 ctx->filter_ctx = r; |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
124 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
125 #if (NGX_HAVE_FILE_AIO) |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
126 if (ngx_file_aio && clcf->aio == NGX_HTTP_AIO_ON) { |
6004 | 127 ctx->aio_handler = ngx_http_copy_aio_handler; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
128 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
129 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
130 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
131 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
132 if (clcf->aio == NGX_HTTP_AIO_THREADS) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
133 ctx->thread_handler = ngx_http_copy_thread_handler; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
134 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
135 #endif |
9300
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
136 } |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
137 |
9300
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
138 if (!r->request_output) { |
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
139 for (cl = in; cl; cl = cl->next) { |
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
140 if (ngx_buf_size(cl->buf)) { |
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
141 r->request_output = 1; |
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
142 break; |
5be23505292b
SSI: fixed incorrect or duplicate stub output.
Maxim Dounin <mdounin@mdounin.ru>
parents:
9203
diff
changeset
|
143 } |
3518
eb3aaf8bd2a9
fix SSI include stub for valid empty responses
Igor Sysoev <igor@sysoev.ru>
parents:
3294
diff
changeset
|
144 } |
60
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
145 } |
50186b49f2ad
nginx-0.0.1-2003-02-11-10:14:40 import
Igor Sysoev <igor@sysoev.ru>
parents:
59
diff
changeset
|
146 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
147 #if (NGX_HAVE_FILE_AIO || NGX_THREADS) |
3119
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3110
diff
changeset
|
148 ctx->aio = r->aio; |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3110
diff
changeset
|
149 #endif |
4c90c9129a82
fix case when the output filter should add incoming buffers
Igor Sysoev <igor@sysoev.ru>
parents:
3110
diff
changeset
|
150 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
151 rc = ngx_output_chain(ctx, in); |
583 | 152 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
153 if (ctx->in == NULL) { |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
154 r->buffered &= ~NGX_HTTP_COPY_BUFFERED; |
3071
ffc270f696ed
retry aio sendfile if data are ready
Igor Sysoev <igor@sysoev.ru>
parents:
3070
diff
changeset
|
155 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
156 } else { |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
157 r->buffered |= NGX_HTTP_COPY_BUFFERED; |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
158 } |
3065 | 159 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
160 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, |
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
161 "http copy filter: %i \"%V?%V\"", rc, &r->uri, &r->args); |
3071
ffc270f696ed
retry aio sendfile if data are ready
Igor Sysoev <igor@sysoev.ru>
parents:
3070
diff
changeset
|
162 |
5980
ccad84a174e0
Refactored sendfile() AIO preload.
Valentin Bartenev <vbart@nginx.com>
parents:
5498
diff
changeset
|
163 return rc; |
4
c5f071d376e5
nginx-0.0.1-2002-08-22-19:24:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
3
diff
changeset
|
164 } |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
165 |
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
166 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
167 #if (NGX_HAVE_FILE_AIO) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
168 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
169 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
170 ngx_http_copy_aio_handler(ngx_output_chain_ctx_t *ctx, ngx_file_t *file) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
171 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
172 ngx_http_request_t *r; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
173 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
174 r = ctx->filter_ctx; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
175 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
176 file->aio->data = r; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
177 file->aio->handler = ngx_http_copy_aio_event_handler; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
178 |
9202
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
179 ngx_add_timer(&file->aio->event, 60000); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
180 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
181 r->main->blocked++; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
182 r->aio = 1; |
3776
7450029ff51e
file AIO read may be posted inside loop
Igor Sysoev <igor@sysoev.ru>
parents:
3518
diff
changeset
|
183 ctx->aio = 1; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
184 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
185 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
186 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
187 static void |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
188 ngx_http_copy_aio_event_handler(ngx_event_t *ev) |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
189 { |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
190 ngx_event_aio_t *aio; |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
191 ngx_connection_t *c; |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
192 ngx_http_request_t *r; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
193 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
194 aio = ev->data; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
195 r = aio->data; |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
196 c = r->connection; |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
197 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
198 ngx_http_set_log_request(c->log, r); |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
199 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
200 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
201 "http aio: \"%V?%V\"", &r->uri, &r->args); |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
202 |
9202
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
203 if (ev->timedout) { |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
204 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
205 "aio operation took too long"); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
206 ev->timedout = 0; |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
207 return; |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
208 } |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
209 |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
210 if (ev->timer_set) { |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
211 ngx_del_timer(ev); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
212 } |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
213 |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
214 r->main->blocked--; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
215 r->aio = 0; |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
216 |
9203
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
217 if (r->main->terminated) { |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
218 /* |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
219 * trigger connection event handler if the request was |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
220 * terminated |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
221 */ |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
222 |
9203
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
223 c->write->handler(c->write); |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
224 |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
225 } else { |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
226 r->write_event_handler(r); |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
227 ngx_http_run_posted_requests(c); |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
228 } |
3052
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
229 } |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
230 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
231 #endif |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
232 |
6060225e9261
FreeBSD and Linux AIO support
Igor Sysoev <igor@sysoev.ru>
parents:
3050
diff
changeset
|
233 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
234 #if (NGX_THREADS) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
235 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
236 static ngx_int_t |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
237 ngx_http_copy_thread_handler(ngx_thread_task_t *task, ngx_file_t *file) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
238 { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
239 ngx_str_t name; |
7974
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
240 ngx_connection_t *c; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
241 ngx_thread_pool_t *tp; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
242 ngx_http_request_t *r; |
6423
c5f81dcf97a7
Copy filter: fixed sendfile aio handlers to set ctx->aio.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6250
diff
changeset
|
243 ngx_output_chain_ctx_t *ctx; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
244 ngx_http_core_loc_conf_t *clcf; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
245 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
246 r = file->thread_ctx; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
247 |
7974
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
248 if (r->aio) { |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
249 /* |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
250 * tolerate sendfile() calls if another operation is already |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
251 * running; this can happen due to subrequests, multiple calls |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
252 * of the next body filter from a filter, or in HTTP/2 due to |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
253 * a write event on the main connection |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
254 */ |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
255 |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
256 c = r->connection; |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
257 |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
258 #if (NGX_HTTP_V2) |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
259 if (r->stream) { |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
260 c = r->stream->connection->connection; |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
261 } |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
262 #endif |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
263 |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
264 if (task == c->sendfile_task) { |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
265 return NGX_OK; |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
266 } |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
267 } |
555533169506
HTTP/2: fixed "task already active" with sendfile in threads.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6951
diff
changeset
|
268 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
269 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
270 tp = clcf->thread_pool; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
271 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
272 if (tp == NULL) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
273 if (ngx_http_complex_value(r, clcf->thread_pool_value, &name) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
274 != NGX_OK) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
275 { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
276 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
277 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
278 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
279 tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
280 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
281 if (tp == NULL) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
282 ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
283 "thread pool \"%V\" not found", &name); |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
284 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
285 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
286 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
287 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
288 task->event.data = r; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
289 task->event.handler = ngx_http_copy_thread_event_handler; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
290 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
291 if (ngx_thread_task_post(tp, task) != NGX_OK) { |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
292 return NGX_ERROR; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
293 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
294 |
9202
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
295 ngx_add_timer(&task->event, 60000); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
296 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
297 r->main->blocked++; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
298 r->aio = 1; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
299 |
6423
c5f81dcf97a7
Copy filter: fixed sendfile aio handlers to set ctx->aio.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6250
diff
changeset
|
300 ctx = ngx_http_get_module_ctx(r, ngx_http_copy_filter_module); |
c5f81dcf97a7
Copy filter: fixed sendfile aio handlers to set ctx->aio.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6250
diff
changeset
|
301 ctx->aio = 1; |
c5f81dcf97a7
Copy filter: fixed sendfile aio handlers to set ctx->aio.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6250
diff
changeset
|
302 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
303 return NGX_OK; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
304 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
305 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
306 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
307 static void |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
308 ngx_http_copy_thread_event_handler(ngx_event_t *ev) |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
309 { |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
310 ngx_connection_t *c; |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
311 ngx_http_request_t *r; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
312 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
313 r = ev->data; |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
314 c = r->connection; |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
315 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
316 ngx_http_set_log_request(c->log, r); |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
317 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
318 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
319 "http thread: \"%V?%V\"", &r->uri, &r->args); |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
320 |
9202
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
321 if (ev->timedout) { |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
322 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
323 "thread operation took too long"); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
324 ev->timedout = 0; |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
325 return; |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
326 } |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
327 |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
328 if (ev->timer_set) { |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
329 ngx_del_timer(ev); |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
330 } |
e88cdaa0f1ff
AIO operations now add timers (ticket #2162).
Maxim Dounin <mdounin@mdounin.ru>
parents:
7985
diff
changeset
|
331 |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
332 r->main->blocked--; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
333 r->aio = 0; |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
334 |
7975
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
335 #if (NGX_HTTP_V2) |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
336 |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
337 if (r->stream) { |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
338 /* |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
339 * for HTTP/2, update write event to make sure processing will |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
340 * reach the main connection to handle sendfile() in threads |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
341 */ |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
342 |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
343 c->write->ready = 1; |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
344 c->write->active = 0; |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
345 } |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
346 |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
347 #endif |
a7a77549265e
HTTP/2: fixed sendfile() aio handling.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7974
diff
changeset
|
348 |
9203
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
349 if (r->done || r->main->terminated) { |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
350 /* |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
351 * trigger connection event handler if the subrequest was |
9203
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
352 * already finalized (this can happen if the handler is used |
0de20f43db25
Fixed request termination with AIO and subrequests (ticket #2555).
Maxim Dounin <mdounin@mdounin.ru>
parents:
9202
diff
changeset
|
353 * for sendfile() in threads), or if the request was terminated |
6951
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
354 */ |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
355 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
356 c->write->handler(c->write); |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
357 |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
358 } else { |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
359 r->write_event_handler(r); |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
360 ngx_http_run_posted_requests(c); |
ce37362a7a70
Copy filter: wake up subrequests after aio operations.
Maxim Dounin <mdounin@mdounin.ru>
parents:
6423
diff
changeset
|
361 } |
6022
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
362 } |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
363 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
364 #endif |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
365 |
1fdba317ee6d
Added support for offloading read() in thread pools.
Valentin Bartenev <vbart@nginx.com>
parents:
6004
diff
changeset
|
366 |
501 | 367 static void * |
368 ngx_http_copy_filter_create_conf(ngx_conf_t *cf) | |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
369 { |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
370 ngx_http_copy_filter_conf_t *conf; |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
371 |
501 | 372 conf = ngx_palloc(cf->pool, sizeof(ngx_http_copy_filter_conf_t)); |
373 if (conf == NULL) { | |
374 return NULL; | |
375 } | |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
376 |
141
656d468f4ead
nginx-0.0.1-2003-10-08-19:32:54 import
Igor Sysoev <igor@sysoev.ru>
parents:
135
diff
changeset
|
377 conf->bufs.num = 0; |
10
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
378 |
4f3879d9b6f6
nginx-0.0.1-2002-09-11-19:18:33 import
Igor Sysoev <igor@sysoev.ru>
parents:
9
diff
changeset
|
379 return conf; |
9
6f58641241bb
nginx-0.0.1-2002-09-07-14:14:25 import
Igor Sysoev <igor@sysoev.ru>
parents:
8
diff
changeset
|
380 } |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
381 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
382 |
501 | 383 static char * |
384 ngx_http_copy_filter_merge_conf(ngx_conf_t *cf, void *parent, void *child) | |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
385 { |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
386 ngx_http_copy_filter_conf_t *prev = parent; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
387 ngx_http_copy_filter_conf_t *conf = child; |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
388 |
6250
0256738454dc
Increased the default number of output buffers.
Valentin Bartenev <vbart@nginx.com>
parents:
6022
diff
changeset
|
389 ngx_conf_merge_bufs_value(conf->bufs, prev->bufs, 2, 32768); |
44
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
390 |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
391 return NULL; |
0e81ac0bb3e2
nginx-0.0.1-2003-01-09-08:36:00 import
Igor Sysoev <igor@sysoev.ru>
parents:
43
diff
changeset
|
392 } |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
393 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
394 |
501 | 395 static ngx_int_t |
681 | 396 ngx_http_copy_filter_init(ngx_conf_t *cf) |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
397 { |
4542
586969d972b9
Local variable "ngx_http_next_filter" renamed to "ngx_http_next_body_filter"
Ruslan Ermilov <ru@nginx.com>
parents:
4415
diff
changeset
|
398 ngx_http_next_body_filter = ngx_http_top_body_filter; |
334
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
399 ngx_http_top_body_filter = ngx_http_copy_filter; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
400 |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
401 return NGX_OK; |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
402 } |
af451db3fe99
nginx-0.0.3-2004-05-12-09:37:55 import
Igor Sysoev <igor@sysoev.ru>
parents:
327
diff
changeset
|
403 |