curl/docs/libcurl
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
..
opts CURLOPT_RESOLVE.md: mention hostname can be wildcard ('*') 2024-06-23 10:29:22 +02:00
.gitignore gitignore: the generated libcurl-symbols.md 2024-01-25 16:34:06 +01:00
ABI.md docs: use present tense 2024-02-27 09:47:21 +01:00
CMakeLists.txt cmake: use namespaced custom target names 2024-04-09 21:20:54 +00:00
curl_easy_cleanup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_duphandle.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_escape.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_getinfo.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_header.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_easy_init.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_nextheader.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_easy_option_by_id.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_option_by_name.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_option_next.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_pause.md curl_easy_pause.md: use correct defines in example 2024-05-15 23:22:17 +02:00
curl_easy_perform.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_recv.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_reset.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_send.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_setopt.md tcpkeepalive: add CURLOPT_TCP_KEEPCNT and --keepalive-cnt 2024-06-12 09:31:17 +02:00
curl_easy_strerror.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_unescape.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_easy_upkeep.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_escape.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_formadd.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_formfree.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_formget.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_free.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_getdate.md misc: fix typos, quoting and spelling 2024-05-06 10:35:53 +02:00
curl_getenv.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_global_cleanup.md dllmain: Call OpenSSL thread cleanup for Windows and Cygwin 2024-04-24 04:04:25 -04:00
curl_global_init_mem.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_global_init.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_global_sslset.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_global_trace.md ftp: add tracing support 2024-05-10 23:39:48 +02:00
curl_mime_addpart.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_data_cb.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_data.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_encoder.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_filedata.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_filename.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_free.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_headers.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_init.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_name.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_subparts.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mime_type.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_mprintf.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_add_handle.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_assign.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_cleanup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_fdset.md lib: add curl_multi_waitfds 2024-04-09 16:53:40 +02:00
curl_multi_get_handles.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_info_read.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_init.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_perform.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_poll.md curl_multi_poll.md: expand the example with an custom file descriptor 2024-06-01 00:24:55 +02:00
curl_multi_remove_handle.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_setopt.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_socket_action.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_socket_all.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_socket.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_strerror.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_timeout.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_multi_wait.md misc: fix typos, quoting and spelling 2024-05-06 10:35:53 +02:00
curl_multi_waitfds.md curl_multi_waitfds.md: add protocol mention 2024-04-09 16:59:28 +02:00
curl_multi_wakeup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_pushheader_byname.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_pushheader_bynum.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_share_cleanup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_share_init.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_share_setopt.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_share_strerror.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_slist_append.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_slist_free_all.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_strequal.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_strnequal.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_unescape.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_url_cleanup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_url_dup.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_url_get.md urlapi: add CURLU_NO_GUESS_SCHEME 2024-06-01 23:51:42 +02:00
curl_url_set.md curl_url_set.md: libcurl only parses :// URLs 2024-05-30 08:30:17 +02:00
curl_url_strerror.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_url.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_version_info.md version: add "ECH" as a feature 2024-04-16 13:24:08 +02:00
curl_version.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
curl_ws_meta.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
curl_ws_recv.md docs/libcurl: add TLS backend info for all TLS options 2024-03-22 14:07:55 +01:00
curl_ws_send.md docs: make each libcurl man specify protocol(s) 2024-03-21 15:27:06 +01:00
libcurl-easy.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-env-dbg.md lib: graceful connection shutdown 2024-06-26 08:33:17 +02:00
libcurl-env.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-errors.md TLS: add support for ECH (Encrypted Client Hello) 2024-04-16 08:10:53 +02:00
libcurl-multi.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-security.md docs: reference non deprecated libcurl options 2024-06-14 13:24:41 +02:00
libcurl-share.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-thread.md dllmain: Call OpenSSL thread cleanup for Windows and Cygwin 2024-04-24 04:04:25 -04:00
libcurl-tutorial.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-url.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl-ws.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
libcurl.m4 misc: Fix typos in docs and lib 2024-03-01 09:59:48 +01:00
libcurl.md docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
Makefile.am docs: dist curl*.1 and install without perl 2024-02-20 10:35:13 +01:00
Makefile.inc lib: add curl_multi_waitfds 2024-04-09 16:53:40 +02:00
mksymbolsmanpage.pl docs/libcurl: generate PROTOCOLS from meta-data 2024-03-23 18:13:03 +01:00
symbols-in-versions tcpkeepalive: add CURLOPT_TCP_KEEPCNT and --keepalive-cnt 2024-06-12 09:31:17 +02:00
symbols.pl