curl/docs
Stefan Eissing c9b95c0bb3
lib: graceful connection shutdown
When libcurl discards a connection there are two phases this may go
through: "shutdown" and "closing". If a connection is aborted, the
shutdown phase is skipped and it is closed right away.

The connection filters attached to the connection implement the phases
in their `do_shutdown()` and `do_close()` callbacks. Filters carry now a
`shutdown` flags next to `connected` to keep track of the shutdown
operation.

Filters are shut down from top to bottom. If a filter is not connected,
its shutdown is skipped. Notable filters that *do* something during
shutdown are HTTP/2 and TLS. HTTP/2 sends the GOAWAY frame. TLS sends
its close notify and expects to receive a close notify from the server.

As sends and receives may EAGAIN on the network, a shutdown is often not
successful right away and needs to poll the connection's socket(s). To
facilitate this, such connections are placed on a new shutdown list
inside the connection cache.

Since managing this list requires the cooperation of a multi handle,
only the connection cache belonging to a multi handle is used. If a
connection was in another cache when being discarded, it is removed
there and added to the multi's cache. If no multi handle is available at
that time, the connection is shutdown and closed in a one-time,
best-effort attempt.

When a multi handle is destroyed, all connection still on the shutdown
list are discarded with a final shutdown attempt and close. In curl
debug builds, the environment variable `CURL_GRACEFUL_SHUTDOWN` can be
set to make this graceful with a timeout in milliseconds given by the
variable.

The shutdown list is limited to the max number of connections configured
for a multi cache. Set via CURLMOPT_MAX_TOTAL_CONNECTIONS. When the
limit is reached, the oldest connection on the shutdown list is
discarded.

- In multi_wait() and multi_waitfds(), collect all connection caches
  involved (each transfer might carry its own) into a temporary list.
  Let each connection cache on the list contribute sockets and
  POLLIN/OUT events it's connections are waiting for.

- in multi_perform() collect the connection caches the same way and let
  them peform their maintenance. This will make another non-blocking
  attempt to shutdown all connections on its shutdown list.

- for event based multis (multi->socket_cb set), add the sockets and
  their poll events via the callback. When `multi_socket()` is invoked
  for a socket not known by an active transfer, forward this to the
  multi's cache for processing. On closing a connection, remove its
  socket(s) via the callback.

TLS connection filters MUST NOT send close nofity messages in their
`do_close()` implementation. The reason is that a TLS close notify
signals a success. When a connection is aborted and skips its shutdown
phase, the server needs to see a missing close notify to detect
something has gone wrong.

A graceful shutdown of FTP's data connection is performed implicitly
before regarding the upload/download as complete and continuing on the
control connection. For FTP without TLS, there is just the socket close
happening. But with TLS, the sent/received close notify signals that the
transfer is complete and healthy. Servers like `vsftpd` verify that and
reject uploads without a TLS close notify.

- added test_19_* for shutdown related tests
- test_19_01 and test_19_02 test for TCP RST packets
  which happen without a graceful shutdown and should
  no longer appear otherwise.
- add test_19_03 for handling shutdowns by the server
- add test_19_04 for handling shutdowns by curl
- add test_19_05 for event based shutdowny by server
- add test_30_06/07 and test_31_06/07 for shutdown checks
  on FTP up- and downloads.

Closes #13976
2024-06-26 08:33:17 +02:00
..
cmdline-opts tidy-up: more whitespace 2024-06-25 14:40:44 +02:00
examples examples: add missing binaries to .gitignore 2024-06-14 13:25:55 +02:00
libcurl lib: graceful connection shutdown 2024-06-26 08:33:17 +02:00
.gitignore
ALTSVC.md
BINDINGS.md BINDINGS: update java link to one that exists 2024-06-14 09:47:47 +02:00
BUFQ.md
BUFREF.md
BUG-BOUNTY.md BUG-BOUNTY.md: clarify the third party situation 2024-05-14 16:23:42 +02:00
BUGS.md
CHECKSRC.md
CIPHERS.md
CLIENT-READERS.md
CLIENT-WRITERS.md
CMakeLists.txt cmake: whitespace, formatting/tidy-up in comments 2024-05-27 18:07:10 +02:00
CODE_OF_CONDUCT.md
CODE_REVIEW.md
CODE_STYLE.md
CONNECTION-FILTERS.md
CONTRIBUTE.md
curl-config.md
CURL-DISABLE.md
CURLDOWN.md
DEPRECATE.md noproxy: patterns need to be comma separated 2024-06-01 12:25:13 +02:00
DISTROS.md DISTROS: add MSYS2 (native) links 2024-06-11 00:01:10 +02:00
DYNBUF.md
EARLY-RELEASE.md
ECH.md GHA: detect and warn for more English contractions 2024-06-13 16:21:09 +02:00
EXPERIMENTAL.md EXPERIMENTAL: add graduation requirements for each feature 2024-05-06 17:05:04 +02:00
FAQ
FEATURES.md
GOVERNANCE.md
HELP-US.md
HISTORY.md
HSTS.md
HTTP2.md
HTTP3.md
HTTP-COOKIES.md
HYPER.md
INSTALL
INSTALL-CMAKE.md
INSTALL.md
INTERNALS.md
IPFS.md
KNOWN_BUGS KNOWN_BUGS: TFTP tests fail on OpenBSD 2024-06-19 12:54:19 +02:00
MAIL-ETIQUETTE.md
Makefile.am docs/Makefile.am: make curl-config.1 install 2024-05-22 09:26:55 +02:00
MANUAL.md
mk-ca-bundle.md
MQTT.md
NEW-PROTOCOL.md
options-in-versions tcpkeepalive: add CURLOPT_TCP_KEEPCNT and --keepalive-cnt 2024-06-12 09:31:17 +02:00
PARALLEL-TRANSFERS.md
README.md
RELEASE-PROCEDURE.md
ROADMAP.md
RUSTLS.md
SECURITY-ADVISORY.md
SPONSORS.md
SSL-PROBLEMS.md
SSLCERTS.md tidy-up: use consistent casing for Windows directories 2024-05-30 14:40:12 +02:00
THANKS THANKS: add contributors from 8.8.0 2024-05-22 07:54:25 +02:00
THANKS-filter
TheArtOfHttpScripting.md
TODO TODO: -h option 2024-06-23 23:07:13 +02:00
URL-SYNTAX.md
VERSIONS.md
VULN-DISCLOSURE-POLICY.md VULN-DISCLOSURE-POLICY: NULL dereferences and crashes 2024-06-19 12:53:35 +02:00
WEBSOCKET.md

curl logo

Documentation

You find a mix of various documentation in this directory and subdirectories, using several different formats. Some of them are not ideal for reading directly in your browser.

If you would rather see the rendered version of the documentation, check out the curl website's documentation section for general curl stuff or the libcurl section for libcurl related documentation.