master
1#***************************************************************************
2# _ _ ____ _
3# Project ___| | | | _ \| |
4# / __| | | | |_) | |
5# | (__| |_| | _ <| |___
6# \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24#
25import logging
26import os
27import re
29import pytest
30from testenv import CurlClient, Env, LocalClient
32log = logging.getLogger(__name__)
35class TestShutdown:
37 @pytest.fixture(autouse=True, scope='class')
38 @classmethod
39 def _class_scope(cls, env, httpd):
40 indir = httpd.docs_dir
41 env.make_data_file(indir=indir, fname="data-10k", fsize=10 * 1024)
42 env.make_data_file(indir=indir, fname="data-100k", fsize=100 * 1024)
43 env.make_data_file(indir=indir, fname="data-1m", fsize=1024 * 1024)
45 # check with `tcpdump` that we see curl TCP RST packets
46 @pytest.mark.skipif(condition=not Env.tcpdump(), reason="tcpdump not available")
47 @pytest.mark.parametrize("proto", ['http/1.1'])
48 def test_19_01_check_tcp_rst(self, env: Env, httpd, proto):
49 if env.ci_run:
50 pytest.skip("seems not to work in CI")
51 # timing critical, disable trace overrides
52 run_env = os.environ.copy()
53 if 'CURL_DEBUG' in run_env:
54 del run_env['CURL_DEBUG']
55 curl = CurlClient(env=env, run_env=run_env)
56 port = env.port_for(alpn_proto=proto)
57 url = f'https://{env.domain1}:{port}/data.json?[0-1]'
58 r = curl.http_download(urls=[url], alpn_proto=proto, with_tcpdump=True, extra_args=[
59 '--parallel'
60 ])
61 r.check_response(http_status=200, count=2)
62 assert r.tcpdump
63 assert len(r.tcpdump.get_rsts(ports=[port])) != 0, f'Expected TCP RSTs packets: {r.tcpdump.stderr}'
65 # check with `tcpdump` that we do NOT see TCP RST when CURL_GRACEFUL_SHUTDOWN set
66 @pytest.mark.skipif(condition=not Env.tcpdump(), reason="tcpdump not available")
67 @pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
68 def test_19_02_check_shutdown(self, env: Env, httpd, proto):
69 if not env.curl_is_debug():
70 pytest.skip('only works for curl debug builds')
71 run_env = os.environ.copy()
72 run_env.update({
73 'CURL_GRACEFUL_SHUTDOWN': '2000',
74 'CURL_DEBUG': 'ssl,tcp,lib-ids,multi'
75 })
76 curl = CurlClient(env=env, run_env=run_env)
77 port = env.port_for(alpn_proto=proto)
78 url = f'https://{env.domain1}:{port}/data.json?[0-1]'
79 r = curl.http_download(urls=[url], alpn_proto=proto, with_tcpdump=True, extra_args=[
80 '--parallel'
81 ])
82 r.check_response(http_status=200, count=2)
83 assert r.tcpdump
84 assert len(r.tcpdump.get_rsts(ports=[port])) == 0, 'Unexpected TCP RST packets'
86 # run downloads where the server closes the connection after each request
87 @pytest.mark.parametrize("proto", ['http/1.1'])
88 def test_19_03_shutdown_by_server(self, env: Env, httpd, proto):
89 if not env.curl_is_debug():
90 pytest.skip('only works for curl debug builds')
91 if not env.curl_is_verbose():
92 pytest.skip('only works for curl with verbose strings')
93 count = 10
94 curl = CurlClient(env=env, run_env={
95 'CURL_GRACEFUL_SHUTDOWN': '2000',
96 'CURL_DEBUG': 'ssl,multi'
97 })
98 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/tweak/?'\
99 f'id=[0-{count-1}]&with_cl&close'
100 r = curl.http_download(urls=[url], alpn_proto=proto)
101 r.check_response(http_status=200, count=count)
102 shutdowns = [line for line in r.trace_lines
103 if re.match(r'.*\[SHUTDOWN] shutdown, done=1', line)]
104 # count-1 shutdowns should definitely happen and the last connection
105 # *may* remain until the share shuts down and just terminates the conn
106 assert len(shutdowns) >= count - 1, f'{shutdowns}'
108 # run downloads with CURLOPT_FORBID_REUSE set, meaning *we* close
109 # the connection after each request
110 @pytest.mark.parametrize("proto", ['http/1.1'])
111 def test_19_04_shutdown_by_curl(self, env: Env, httpd, proto):
112 if not env.curl_is_debug():
113 pytest.skip('only works for curl debug builds')
114 if not env.curl_is_verbose():
115 pytest.skip('only works for curl with verbose strings')
116 count = 10
117 docname = 'data.json'
118 url = f'https://localhost:{env.https_port}/{docname}'
119 client = LocalClient(name='cli_hx_download', env=env, run_env={
120 'CURL_GRACEFUL_SHUTDOWN': '2000',
121 'CURL_DEBUG': 'ssl,multi'
122 })
123 if not client.exists():
124 pytest.skip(f'example client not built: {client.name}')
125 r = client.run(args=[
126 '-n', f'{count}', '-f', '-C', env.ca.cert_file,
127 '-V', proto, url
128 ])
129 r.check_exit_code(0)
130 shutdowns = [line for line in r.trace_lines
131 if re.match(r'.*SHUTDOWN] shutdown, done=1', line)]
132 assert len(shutdowns) == count, f'{shutdowns}'
134 # run event-based downloads with CURLOPT_FORBID_REUSE set, meaning *we* close
135 # the connection after each request
136 @pytest.mark.parametrize("proto", ['http/1.1'])
137 def test_19_05_event_shutdown_by_server(self, env: Env, httpd, proto):
138 if not env.curl_is_debug():
139 pytest.skip('only works for curl debug builds')
140 if not env.curl_is_verbose():
141 pytest.skip('only works for curl with verbose strings')
142 count = 10
143 run_env = os.environ.copy()
144 # forbid connection reuse to trigger shutdowns after transfer
145 run_env['CURL_FORBID_REUSE'] = '1'
146 # make socket receives block 50% of the time to delay shutdown
147 run_env['CURL_DBG_SOCK_RBLOCK'] = '50'
148 run_env['CURL_DEBUG'] = 'ssl,multi,lib-ids'
149 curl = CurlClient(env=env, run_env=run_env)
150 url = f'https://{env.authority_for(env.domain1, proto)}/curltest/tweak/?'\
151 f'id=[0-{count-1}]&with_cl&'
152 r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
153 '--test-event'
154 ])
155 r.check_response(http_status=200, count=count)
156 # check that we closed all connections
157 closings = [line for line in r.trace_lines
158 if re.match(r'.*SHUTDOWN] (force )?closing', line)]
159 assert len(closings) == count, f'{closings}'
160 # check that all connection sockets were removed from event
161 removes = [line for line in r.trace_lines
162 if re.match(r'.*socket cb: socket \d+ REMOVED', line)]
163 assert len(removes) >= count, f'{removes}'
165 # check graceful shutdown on multiplexed http
166 @pytest.mark.parametrize("proto", Env.http_mplx_protos())
167 def test_19_06_check_shutdown(self, env: Env, httpd, nghttpx, proto):
168 if not env.curl_is_debug():
169 pytest.skip('only works for curl debug builds')
170 if not env.curl_is_verbose():
171 pytest.skip('only works for curl with verbose strings')
172 curl = CurlClient(env=env, run_env={
173 'CURL_GRACEFUL_SHUTDOWN': '2000',
174 'CURL_DEBUG': 'all'
175 })
176 url = f'https://{env.authority_for(env.domain1, proto)}/data.json?[0-1]'
177 r = curl.http_download(urls=[url], alpn_proto=proto, with_tcpdump=True, extra_args=[
178 '--parallel'
179 ])
180 r.check_response(http_status=200, count=2)
181 # check connection cache closings
182 shutdowns = [line for line in r.trace_lines
183 if re.match(r'.*SHUTDOWN] shutdown, done=1', line)]
184 assert len(shutdowns) == 1, f'{shutdowns}'
186 # run connection pressure, many small transfers, not reusing connections,
187 # limited total
188 @pytest.mark.parametrize("proto", ['http/1.1'])
189 @pytest.mark.parametrize("share_connect", [False, True])
190 def test_19_07_shutdown_by_curl(self, env: Env, httpd, proto, share_connect):
191 if not env.curl_is_debug():
192 pytest.skip('only works for curl debug builds')
193 count = 500
194 docname = 'data.json'
195 url = f'https://localhost:{env.https_port}/{docname}'
196 client = LocalClient(name='cli_hx_download', env=env, run_env={
197 'CURL_GRACEFUL_SHUTDOWN': '2000',
198 'CURL_DEBUG': 'ssl,multi'
199 })
200 if not client.exists():
201 pytest.skip(f'example client not built: {client.name}')
202 extra_args = ['-S'] if share_connect else [] # share connections
203 r = client.run(args=[
204 '-n', f'{count}', # that many transfers
205 '-C', env.ca.cert_file,
206 '-f', # forbid conn reuse
207 '-m', '10', # max parallel
208 '-T', '5', # max total conns at a time
209 ] + extra_args + ['-V', proto, url])
210 r.check_exit_code(0)
211 shutdowns = [line for line in r.trace_lines
212 if re.match(r'.*SHUTDOWN] shutdown, done=1', line)]
213 # we see less clean shutdowns as total limit forces early closes
214 assert len(shutdowns) < count, f'{shutdowns}'
216 # Strictly event-based transfers, no connection reuse. Connections
217 # whose graceful shutdown cannot finish right away must have their
218 # socket stay registered with the application's socket callback,
219 # or they never make progress and leak until multi cleanup.
220 @pytest.mark.parametrize("proto", ['http/1.1'])
221 def test_19_08_event_shutdown_watched(self, env: Env, httpd, proto):
222 if not env.curl_is_debug():
223 pytest.skip('only works for curl debug builds')
224 count = 5
225 docname = 'data.json'
226 url = f'https://localhost:{env.https_port}/{docname}'
227 client = LocalClient(name='cli_ev_download', env=env, run_env={
228 # make socket receives block often, so the TLS shutdown
229 # cannot finish on its first attempt
230 'CURL_DBG_SOCK_RBLOCK': '90',
231 'CURL_DEBUG': 'ssl,multi'
232 })
233 if not client.exists():
234 pytest.skip(f'example client not built: {client.name}')
235 r = client.run(args=[
236 '-n', f'{count}', '-C', env.ca.cert_file, url
237 ])
238 r.check_exit_code(0)
239 m = None
240 for line in r.stderr.splitlines():
241 m = re.match(r'.*\[ev] final: watched=(\d+) socks_left=(\d+)', line)
242 if m:
243 break
244 assert m, f'no client event summary found: {r.stderr}'
245 # shutdown sockets were watched after transfers finished and
246 # all shutdowns finished within the event loop
247 assert int(m.group(1)) > 0, f'{r.stderr}'
248 assert int(m.group(2)) == 0, f'{r.stderr}'
Diagnostics4 git calls · 36 ms
CallStatusSizeTime036 ms
discover200152 B3 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200149 B · hit3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=149 git.pkt.payload.max=78 git.ls_refs.count=2 git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit2 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=2 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=2 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=10 git.pkt.data=8 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=293470 git.pkt.payload.max=65516 git.sideband.band1.bytes=293354 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=87 git.pack.bytes=293354 git.pack.ofs_delta=0 git.pack.ref_delta=1 git.pack.chain.max=1 git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0 git.pack.full=86Open pack map
fetch2003.0 KiB · hit31 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=30 git.response.bytes=3042 git.response.cache=HIT git.response.duration_ms=31 git.fetch.wants=ea8d013df9e6519d39676013cf0012da420942de git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=3042 git.pkt.payload.max=3021 git.sideband.band1.bytes=3020 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
- Ref
- refs/heads/master
- Commit
- 31c911efe5652725e930f4d2e60c9060e5f6646d
- cf-ray
- a5e2f4bdbb4e7089
- Request
- e7bf78a5…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format