Mercurial > hg > nginx
annotate src/event/ngx_event_posted.c @ 7694:09fb2135a589
SSL: fixed shutdown handling.
Previously, bidirectional shutdown never worked, due to two issues
in the code:
1. The code only tested SSL_ERROR_WANT_READ and SSL_ERROR_WANT_WRITE
when there was an error in the error queue, which cannot happen.
The bug was introduced in an attempt to fix unexpected error logging
as reported with OpenSSL 0.9.8g
(http://mailman.nginx.org/pipermail/nginx/2008-January/003084.html).
2. The code never called SSL_shutdown() for the second time to wait for
the peer's close_notify alert.
This change fixes both issues.
Note that after this change bidirectional shutdown is expected to work for
the first time, so c->ssl->no_wait_shutdown now makes a difference. This
is not a problem for HTTP code which always uses c->ssl->no_wait_shutdown,
but might be a problem for stream and mail code, as well as 3rd party
modules.
To minimize the effect of the change, the timeout, which was used to be 30
seconds and not configurable, though never actually used, is now set to
3 seconds. It is also expanded to apply to both SSL_ERROR_WANT_READ and
SSL_ERROR_WANT_WRITE, so timeout is properly set if writing to the socket
buffer is not possible.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 10 Aug 2020 18:52:09 +0300 |
parents | f1720934c45b |
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:
381
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:
381
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:
381
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:
381
diff
changeset
|
6 |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #include <ngx_config.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #include <ngx_core.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 #include <ngx_event.h> |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
13 ngx_queue_t ngx_posted_accept_events; |
7584
9d2ad2fb4423
SSL: available bytes handling (ticket #1431).
Maxim Dounin <mdounin@mdounin.ru>
parents:
5821
diff
changeset
|
14 ngx_queue_t ngx_posted_next_events; |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
15 ngx_queue_t ngx_posted_events; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
17 |
563 | 18 void |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
19 ngx_event_process_posted(ngx_cycle_t *cycle, ngx_queue_t *posted) |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
20 { |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
21 ngx_queue_t *q; |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
22 ngx_event_t *ev; |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
23 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
24 while (!ngx_queue_empty(posted)) { |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
25 |
5821
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
26 q = ngx_queue_head(posted); |
3f5f0ab59b35
Events: processing of posted events changed from LIFO to FIFO.
Valentin Bartenev <vbart@nginx.com>
parents:
5820
diff
changeset
|
27 ev = ngx_queue_data(q, ngx_event_t, queue); |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
28 |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
29 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
461 | 30 "posted event %p", ev); |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
31 |
375
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
374
diff
changeset
|
32 ngx_delete_posted_event(ev); |
744ccb59062d
nginx-0.0.7-2004-07-02-19:54:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
374
diff
changeset
|
33 |
509 | 34 ev->handler(ev); |
306
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
35 } |
6b91bfbc4123
nginx-0.0.3-2004-04-05-00:32:09 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
36 } |
7612
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
37 |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
38 |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
39 void |
7617
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
40 ngx_event_move_posted_next(ngx_cycle_t *cycle) |
7612
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
41 { |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
42 ngx_queue_t *q; |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
43 ngx_event_t *ev; |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
44 |
7617
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
45 for (q = ngx_queue_head(&ngx_posted_next_events); |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
46 q != ngx_queue_sentinel(&ngx_posted_next_events); |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
47 q = ngx_queue_next(q)) |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
48 { |
7612
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
49 ev = ngx_queue_data(q, ngx_event_t, queue); |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
50 |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
51 ngx_log_debug1(NGX_LOG_DEBUG_EVENT, cycle->log, 0, |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
52 "posted next event %p", ev); |
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
53 |
7617
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
54 ev->ready = 1; |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
55 ev->available = -1; |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
56 } |
7612
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
57 |
7617
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
58 ngx_queue_add(&ngx_posted_events, &ngx_posted_next_events); |
f1720934c45b
SSL: reworked posted next events again.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7612
diff
changeset
|
59 ngx_queue_init(&ngx_posted_next_events); |
7612
1ce3f01a4355
SSL: reworked posted next events.
Maxim Dounin <mdounin@mdounin.ru>
parents:
7584
diff
changeset
|
60 } |