]> git.kaiwu.me - nginx.git/commit
Added proper handling of connection close phases.
authorVladimir Homutov <vl@nginx.com>
Thu, 23 Apr 2020 10:41:08 +0000 (13:41 +0300)
committerVladimir Homutov <vl@nginx.com>
Thu, 23 Apr 2020 10:41:08 +0000 (13:41 +0300)
commit26b7056972b52c210d43ff52d018b952cce109a5
tree9ff5d3010ebf6d0ae1bb456d12a238cb5d3777f7
parentc8edca31379455d4b2f7b6feae6536c3bd30a4de
Added proper handling of connection close phases.

There are following flags in quic connection:

closing  - true, when a connection close is initiated, for whatever reason
draining - true, when a CC frame is received from peer

The following state machine is used for closing:

 +------------------+
 |       I/HS/AD    |
 +------------------+
 |        |       |
 |        |       V
 |        |   immediate close initiated:
 |        |     reasons: close by top-level protocol, fatal error
 |        |     + sends CC (probably with app-level message)
 |        |     + starts close_timer: 3 * PTO (current probe timeout)
 |        |       |
 |        |       V
 |        |   +---------+  - Reply to input with CC (rate-limited)
 |        |   | CLOSING |  - Close/Reset all streams
 |        |   +---------+
 |        |       |    |
 |        V       V    |
 |       receives CC   |
 |          |          |
idle        |          |
timer       |          |
 |          V          |
 |      +----------+   |  - MUST NOT send anything (MAY send a single CC)
 |      | DRAINING |   |  - if not already started, starts close_timer: 3 * PTO
 |      +----------+   |  - if not already done, close all streams
 |          |          |
 |          |          |
 |       close_timer fires
 |          |
 V          V
 +------------------------+
 |       CLOSED           | - clean up all the resources, drop connection
 +------------------------+   state completely

The ngx_quic_close_connection() function gets an "rc" argument, that signals
reason of connection closing:
    NGX_OK    - initiated by application (i.e. http/3), follow state machine
    NGX_DONE  - timedout (while idle or draining)
    NGX_ERROR - fatal error, destroy connection immediately

The PTO calculations are not yet implemented, hardcoded value of 5s is used.
src/event/ngx_event_quic.c
src/event/ngx_event_quic.h