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#include "unitcheck.h"
26#ifdef HAVE_NETINET_IN_H
27#include <netinet/in.h>
28#endif
29#ifdef HAVE_NETINET_IN6_H
30#include <netinet/in6.h>
31#endif
32#ifdef HAVE_NETDB_H
33#include <netdb.h>
34#endif
35#ifdef HAVE_ARPA_INET_H
36#include <arpa/inet.h>
37#endif
38#ifdef __VMS
39#include <in.h>
40#include <inet.h>
41#endif
43#include "urldata.h"
44#include "connect.h"
45#include "cfilters.h"
46#include "cf-ip-happy.h"
47#include "multiif.h"
48#include "select.h"
49#include "sockaddr.h"
50#include "curl_addrinfo.h"
51#include "curl_trc.h"
53static CURLcode t2600_setup(CURL **easy)
54{
55 CURLcode result = CURLE_OK;
57 global_init(CURL_GLOBAL_ALL);
58 *easy = curl_easy_init();
59 if(!*easy) {
60 curl_global_cleanup();
61 return CURLE_OUT_OF_MEMORY;
62 }
63 curl_global_trace("all");
64 curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
65 return result;
66}
68static void t2600_stop(CURL *easy)
69{
70 curl_easy_cleanup(easy);
71 curl_global_cleanup();
72}
74struct test_case {
75 int id;
76 const char *url;
77 const char *resolve_info;
78 long ip_version;
79 timediff_t connect_timeout_ms;
80 timediff_t he_timeout_ms;
81 timediff_t cf4_fail_delay_ms;
82 timediff_t cf6_fail_delay_ms;
84 int exp_cf4_creations;
85 int exp_cf6_creations;
86 timediff_t min_duration_ms;
87 timediff_t max_duration_ms;
88 CURLcode result_exp;
89 const char *pref_family;
90 uint32_t max_concurrent;
91};
93struct ai_family_stats {
94 const char *family;
95 int creations;
96 timediff_t first_created;
97 timediff_t last_created;
98};
100struct test_result {
101 CURLcode result;
102 struct curltime started;
103 struct curltime ended;
104 struct ai_family_stats cf4;
105 struct ai_family_stats cf6;
106 uint32_t max_concurrent;
107 uint32_t ongoing;
108};
110static const struct test_case *current_tc;
111static struct test_result *current_tr;
112static int test_idx;
114struct cf_test_ctx {
115 int idx;
116 int ai_family;
117 uint8_t transport_peer;
118 char id[16];
119 struct curltime started;
120 timediff_t fail_delay_ms;
121 struct ai_family_stats *stats;
122};
124static void cf_test_destroy(struct Curl_cfilter *cf, struct Curl_easy *data)
125{
126 struct cf_test_ctx *ctx = cf->ctx;
127 current_tr->ongoing--;
128 infof(data, "%04dms: cf[%s] destroyed, now %u ongoing",
129 (int)curlx_timediff_ms(curlx_now(), current_tr->started),
130 ctx->id, current_tr->ongoing);
131 curlx_free(ctx);
132 cf->ctx = NULL;
133}
135static CURLcode cf_test_connect(struct Curl_cfilter *cf,
136 struct Curl_easy *data,
137 bool *done)
138{
139 struct cf_test_ctx *ctx = cf->ctx;
140 timediff_t duration_ms;
142 (void)data;
143 *done = FALSE;
144 duration_ms = curlx_timediff_ms(curlx_now(), ctx->started);
145 if(duration_ms >= ctx->fail_delay_ms) {
146 infof(data, "%04dms: cf[%s] fail delay reached",
147 (int)duration_ms, ctx->id);
148 return CURLE_COULDNT_CONNECT;
149 }
150 if(duration_ms) {
151 infof(data, "%04dms: cf[%s] continuing", (int)duration_ms, ctx->id);
152 curlx_wait_ms(10);
153 }
154 Curl_expire(data, ctx->fail_delay_ms - duration_ms, EXPIRE_TIMEOUT);
155 return CURLE_OK;
156}
158static CURLcode cf_test_adjust_pollset(struct Curl_cfilter *cf,
159 struct Curl_easy *data,
160 struct easy_pollset *ps)
161{
162 struct cf_test_ctx *ctx = cf->ctx;
163 /* for testing, give one socket with events back */
164 return Curl_pollset_set(data, ps, ctx->idx, TRUE, TRUE);
165}
167static CURLcode cf_test_create(struct Curl_cfilter **pcf,
168 struct Curl_easy *data,
169 struct Curl_peer *origin,
170 struct Curl_peer *peer,
171 uint8_t transport_peer,
172 struct connectdata *conn,
173 struct Curl_sockaddr_ex *addr,
174 struct Curl_peer *tunnel_peer,
175 uint8_t transport_above)
176{
177 static const struct Curl_cftype cft_test = {
178 "TEST",
179 CF_TYPE_IP_CONNECT,
180 CURL_LOG_LVL_NONE,
181 cf_test_destroy,
182 cf_test_connect,
183 Curl_cf_def_shutdown,
184 cf_test_adjust_pollset,
185 Curl_cf_def_data_pending,
186 Curl_cf_def_send,
187 Curl_cf_def_recv,
188 Curl_cf_def_cntrl,
189 Curl_cf_def_conn_is_alive,
190 Curl_cf_def_conn_keep_alive,
191 Curl_cf_def_query,
192 };
194 struct cf_test_ctx *ctx = NULL;
195 struct Curl_cfilter *cf = NULL;
196 timediff_t created_at;
197 CURLcode result;
199 (void)data;
200 (void)origin;
201 (void)peer;
202 (void)conn;
203 (void)tunnel_peer;
204 (void)transport_above;
205 ctx = curlx_calloc(1, sizeof(*ctx));
206 if(!ctx) {
207 result = CURLE_OUT_OF_MEMORY;
208 goto out;
209 }
210 ctx->idx = test_idx++;
211 ctx->ai_family = addr->family;
212 ctx->transport_peer = transport_peer;
213 ctx->started = curlx_now();
214 current_tr->ongoing++;
215 if(current_tr->ongoing > current_tr->max_concurrent)
216 current_tr->max_concurrent = current_tr->ongoing;
217#ifdef USE_IPV6
218 if(ctx->ai_family == AF_INET6) {
219 ctx->stats = ¤t_tr->cf6;
220 ctx->fail_delay_ms = current_tc->cf6_fail_delay_ms;
221 curl_msprintf(ctx->id, "v6-%d", ctx->stats->creations);
222 ctx->stats->creations++;
223 }
224 else
225#endif
226 {
227 ctx->stats = ¤t_tr->cf4;
228 ctx->fail_delay_ms = current_tc->cf4_fail_delay_ms;
229 curl_msprintf(ctx->id, "v4-%d", ctx->stats->creations);
230 ctx->stats->creations++;
231 }
233 created_at = curlx_timediff_ms(ctx->started, current_tr->started);
234 if(ctx->stats->creations == 1)
235 ctx->stats->first_created = created_at;
236 ctx->stats->last_created = created_at;
237 infof(data, "%04dms: cf[%s] created, now %u ongoing",
238 (int)created_at, ctx->id, current_tr->ongoing);
240 result = Curl_cf_create(&cf, &cft_test, ctx);
241 if(result)
242 goto out;
244 Curl_expire(data, ctx->fail_delay_ms, EXPIRE_TIMEOUT);
246out:
247 *pcf = (!result) ? cf : NULL;
248 if(result) {
249 curlx_free(cf);
250 curlx_free(ctx);
251 }
252 return result;
253}
255static void check_result(const struct test_case *tc, struct test_result *tr)
256{
257 char msg[256];
258 timediff_t duration_ms;
260 duration_ms = curlx_timediff_ms(tr->ended, tr->started);
261 curl_mfprintf(stderr, "%d: test case took %dms\n", tc->id, (int)duration_ms);
263 if(tr->result != tc->result_exp && tr->result != CURLE_OPERATION_TIMEDOUT) {
264 /* on CI we encounter the TIMEOUT result, since images get less CPU
265 * and events are not as sharply timed. */
266 curl_msprintf(msg, "%d: expected result %d but got %d",
267 tc->id, (int)tc->result_exp, (int)tr->result);
268 fail(msg);
269 }
270 if(tr->cf4.creations != tc->exp_cf4_creations) {
271 curl_msprintf(msg, "%d: expected %d IPv4 creations, but got %d",
272 tc->id, tc->exp_cf4_creations, tr->cf4.creations);
273 fail(msg);
274 }
275 if(tr->cf6.creations != tc->exp_cf6_creations) {
276 curl_msprintf(msg, "%d: expected %d IPv6 creations, but got %d",
277 tc->id, tc->exp_cf6_creations, tr->cf6.creations);
278 fail(msg);
279 }
281 duration_ms = curlx_timediff_ms(tr->ended, tr->started);
282 if(duration_ms < tc->min_duration_ms) {
283 curl_msprintf(msg, "%d: expected min duration of %dms, but took %dms",
284 tc->id, (int)tc->min_duration_ms, (int)duration_ms);
285 fail(msg);
286 }
287 if(duration_ms > tc->max_duration_ms) {
288 curl_msprintf(msg, "%d: expected max duration of %dms, but took %dms",
289 tc->id, (int)tc->max_duration_ms, (int)duration_ms);
290 fail(msg);
291 }
292 if(tr->cf6.creations && tr->cf4.creations && tc->pref_family) {
293 /* did IPv4 and IPv6 both, expect the preferred family to start right away
294 * with the other being delayed by the happy_eyeball_timeout */
295 struct ai_family_stats *stats1 = !strcmp(tc->pref_family, "v6") ?
296 &tr->cf6 : &tr->cf4;
297 struct ai_family_stats *stats2 = !strcmp(tc->pref_family, "v6") ?
298 &tr->cf4 : &tr->cf6;
300 if(stats1->first_created > 100) {
301 curl_msprintf(msg, "%d: expected ip%s to start right away, instead "
302 "first attempt made after %dms",
303 tc->id, stats1->family, (int)stats1->first_created);
304 fail(msg);
305 }
306 if(stats2->first_created < tc->he_timeout_ms) {
307 curl_msprintf(msg, "%d: expected ip%s to start delayed after %dms, "
308 "instead first attempt made after %dms",
309 tc->id, stats2->family, (int)tc->he_timeout_ms,
310 (int)stats2->first_created);
311 fail(msg);
312 }
313 }
314 if(tr->max_concurrent != tc->max_concurrent) {
315 curl_msprintf(msg, "%d: expected max %u ongoing, but reported %u",
316 tc->id, tc->max_concurrent, tr->max_concurrent);
317 fail(msg);
318 }
319}
321static void test_connect(CURL *easy, const struct test_case *tc)
322{
323 struct test_result tr;
324 struct curl_slist *list = NULL;
326 debug_set_transport_provider(TRNSPRT_TCP, cf_test_create);
327 current_tc = tc;
328 current_tr = &tr;
330 list = curl_slist_append(NULL, tc->resolve_info);
331 fail_unless(list, "error allocating resolve list entry");
332 curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
333 curl_easy_setopt(easy, CURLOPT_IPRESOLVE, tc->ip_version);
334 curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS,
335 (long)tc->connect_timeout_ms);
336 curl_easy_setopt(easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
337 (long)tc->he_timeout_ms);
339 curl_easy_setopt(easy, CURLOPT_URL, tc->url);
340 memset(&tr, 0, sizeof(tr));
341 tr.cf6.family = "v6";
342 tr.cf4.family = "v4";
344 tr.started = curlx_now();
345 tr.result = curl_easy_perform(easy);
346 tr.ended = curlx_now();
348 curl_easy_setopt(easy, CURLOPT_RESOLVE, NULL);
349 curl_slist_free_all(list);
350 list = NULL;
351 current_tc = NULL;
352 current_tr = NULL;
354 check_result(tc, &tr);
355}
357/*
358 * How these test cases work:
359 * - replace the creation of the TCP socket filter with our test filter
360 * - test filter does nothing and reports failure after configured delay
361 * - we feed addresses into the resolve cache to simulate different cases
362 * - we monitor how many instances of IPv4/IPv6 attempts are made and when
363 * - for mixed families, we expect HAPPY_EYEBALLS_TIMEOUT to trigger
364 *
365 * Max Duration checks needs to be conservative since CI jobs are not
366 * as sharp.
367 */
368#define TURL "http://abc.test:123"
370#define R_FAIL CURLE_COULDNT_CONNECT
371/* timeout values accounting for low cpu resources in CI */
372#define TC_TMOT 90000 /* 90 sec max test duration */
373#define CNCT_TMOT 60000 /* 60sec connect timeout */
375static CURLcode test_unit2600(const char *arg)
376{
377 CURL *easy;
379 UNITTEST_BEGIN(t2600_setup(&easy))
381 static const struct test_case TEST_CASES[] = {
382 /* TIMEOUT_MS, FAIL_MS CREATED DURATION Result, HE_PREF */
383 /* CNCT HE v4 v6 v4 v6 MIN MAX MAX_CONCURRENT */
384 { 1, TURL, "abc.test:123:192.0.2.1", CURL_IPRESOLVE_WHATEVER,
385 CNCT_TMOT, 150, 250, 250, 1, 0, 200, TC_TMOT, R_FAIL, NULL,
386 1 },
387 /* 1 IPv4, fails after ~200ms, reports COULDNT_CONNECT */
388 { 2, TURL, "abc.test:123:192.0.2.1,192.0.2.2", CURL_IPRESOLVE_WHATEVER,
389 CNCT_TMOT, 150, 250, 250, 2, 0, 400, TC_TMOT, R_FAIL, NULL,
390 2 },
391 /* 2 IPv4, fails after ~400ms, reports COULDNT_CONNECT */
392#ifdef USE_IPV6
393 { 3, TURL, "abc.test:123:::1", CURL_IPRESOLVE_WHATEVER,
394 CNCT_TMOT, 150, 250, 250, 0, 1, 200, TC_TMOT, R_FAIL, NULL,
395 1 },
396 /* 1 IPv6, fails after ~200ms, reports COULDNT_CONNECT */
397 { 4, TURL, "abc.test:123:::1,::2", CURL_IPRESOLVE_WHATEVER,
398 CNCT_TMOT, 150, 250, 250, 0, 2, 400, TC_TMOT, R_FAIL, NULL,
399 2 },
400 /* 2 IPv6, fails after ~400ms, reports COULDNT_CONNECT */
401 { 5, TURL, "abc.test:123:192.0.2.1,::1", CURL_IPRESOLVE_WHATEVER,
402 CNCT_TMOT, 150, 250, 250, 1, 1, 350, TC_TMOT, R_FAIL, "v6",
403 2 },
404 /* mixed ip4+6, v6 always first, v4 kicks in on HE, fails after ~350ms */
405 { 6, TURL, "abc.test:123:::1,192.0.2.1", CURL_IPRESOLVE_WHATEVER,
406 CNCT_TMOT, 150, 250, 250, 1, 1, 350, TC_TMOT, R_FAIL, "v6",
407 2 },
408 /* mixed ip6+4, v6 starts, v4 never starts due to high HE, TIMEOUT */
409 { 7, TURL, "abc.test:123:192.0.2.1,::1", CURL_IPRESOLVE_V4,
410 CNCT_TMOT, 150, 500, 500, 1, 0, 400, TC_TMOT, R_FAIL, NULL,
411 1 },
412 /* mixed ip4+6, but only use v4, check it uses full connect timeout,
413 although another address of the 'wrong' family is available */
414 { 8, TURL, "abc.test:123:::1,192.0.2.1", CURL_IPRESOLVE_V6,
415 CNCT_TMOT, 150, 500, 500, 0, 1, 400, TC_TMOT, R_FAIL, NULL,
416 1 },
417 /* mixed ip4+6, but only use v6, check it uses full connect timeout,
418 although another address of the 'wrong' family is available */
419 { 9, TURL, "abc.test:123:::1,192.0.2.1,::2,::3", CURL_IPRESOLVE_WHATEVER,
420 CNCT_TMOT, 50, 400, 400, 1, 3, 550, TC_TMOT, R_FAIL, NULL,
421 4 },
422 /* 1 v4, 3 v6, fails after (3*HE)+400ms, ~550ms, COULDNT_CONNECT */
423 { 10, TURL, "abc.test:123:::1,192.0.2.1,::2,::3,::4,::5,::6,::7,::8",
424 CURL_IPRESOLVE_WHATEVER,
425 CNCT_TMOT, 20, 500, 500, 1, 8, 550, TC_TMOT, R_FAIL, NULL,
426 6 },
427 /* 1 v4, 8 v6, MUST meet limit of 6 concurrent attempts */
429#endif
430 };
432 size_t i;
434 for(i = 0; i < CURL_ARRAYSIZE(TEST_CASES); ++i) {
435 test_connect(easy, &TEST_CASES[i]);
436 }
438 UNITTEST_END(t2600_stop(easy))
439}
Diagnostics4 git calls · 67 ms
CallStatusSizeTime067 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 · hit5 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=5 git.response.bytes=149 git.response.cache=HIT git.response.duration_ms=5 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 · hit22 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=4 git.response.bytes=293470 git.response.cache=HIT git.response.duration_ms=22 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
fetch2004.4 KiB · hit40 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=40 git.response.bytes=4503 git.response.cache=HIT git.response.duration_ms=40 git.fetch.wants=c77c3a4fe7e29ed6a80c100f18496ee85d3bd49e 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=4503 git.pkt.payload.max=4482 git.sideband.band1.bytes=4481 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
- a5e2fb8dcb70cf81
- Request
- 866a6e44…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format