Artifactspublic-v0

curl

master
ply4 git calls1.0 s291 KiB2 cachedprotocol v2
489 lines15 KiBRaw
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 "first.h"
26#if defined(HAVE_GETRLIMIT) && defined(HAVE_SETRLIMIT)
28#define T537_SAFETY_MARGIN 11
30#if defined(_WIN32) || defined(MSDOS)
31#define DEV_NULL "NUL"
32#else
33#define DEV_NULL "/dev/null"
34#endif
36static int *t537_testfd = NULL;
37static struct rlimit t537_num_open;
38static char t537_msgbuff[256];
40static void t537_store_errmsg(const char *msg, int err)
42 if(!err)
43 curl_msnprintf(t537_msgbuff, sizeof(t537_msgbuff), "%s", msg);
44 else {
45 char errbuf[STRERROR_LEN];
46 curl_msnprintf(t537_msgbuff, sizeof(t537_msgbuff), "%s, errno %d, %s", msg,
47 err, curlx_strerror(err, errbuf, sizeof(errbuf)));
48 }
51static void t537_close_file_descriptors(void)
53 for(t537_num_open.rlim_cur = 0;
54 t537_num_open.rlim_cur < t537_num_open.rlim_max;
55 t537_num_open.rlim_cur++)
56 if(t537_testfd[t537_num_open.rlim_cur] > 0)
57 curlx_close(t537_testfd[t537_num_open.rlim_cur]);
58 curlx_safefree(t537_testfd);
61static int t537_fopen_works(void)
63 FILE *fpa[3];
64 int i;
65 int ret = 1;
67 for(i = 0; i < 3; i++) {
68 fpa[i] = NULL;
69 }
70 for(i = 0; i < 3; i++) {
71 fpa[i] = curlx_fopen(DEV_NULL, FOPEN_READTEXT);
72 if(!fpa[i]) {
73 t537_store_errmsg("fopen failed", errno);
74 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
75 ret = 0;
76 break;
77 }
78 }
79 for(i = 0; i < 3; i++) {
80 if(fpa[i])
81 curlx_fclose(fpa[i]);
82 }
83 return ret;
86static int t537_test_rlimit(int keep_open)
88 int *tmpfd;
89 rlim_t nitems, i;
90 int *memchunk = NULL;
91 struct rlimit rl;
92 char strbuff[256];
93 char strbuff1[81];
95 /* get initial open file limits */
97 if(getrlimit(RLIMIT_NOFILE, &rl)) {
98 t537_store_errmsg("getrlimit() failed", errno);
99 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
100 return -1;
101 }
103 /* show initial open file limits */
105 tutil_rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
106 curl_mfprintf(stderr, "initial soft limit: %s\n", strbuff);
108 tutil_rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
109 curl_mfprintf(stderr, "initial hard limit: %s\n", strbuff);
111 /* If the OS allows a HUGE number of open files, we do not run.
112 * Modern debian sid reports a limit of 134217724 and this tests
113 * takes minutes. */
114#define LIMIT_CAP (256 * 1024)
115 if(rl.rlim_cur > LIMIT_CAP) {
116 curl_mfprintf(stderr, "soft limit above %ld, not running\n",
117 (long)LIMIT_CAP);
118 return -2;
119 }
121 /*
122 * if soft limit and hard limit are different we ask the
123 * system to raise soft limit all the way up to the hard
124 * limit. Due to some other system limit the soft limit
125 * might not be raised up to the hard limit. So from this
126 * point the resulting soft limit is our limit. Trying to
127 * open more than soft limit file descriptors does fail.
128 */
130 if(rl.rlim_cur != rl.rlim_max) {
132#ifdef OPEN_MAX
133 if((rl.rlim_cur > 0) &&
134 (rl.rlim_cur < OPEN_MAX)) {
135 curl_mfprintf(stderr, "raising soft limit up to OPEN_MAX\n");
136 rl.rlim_cur = OPEN_MAX;
137 if(setrlimit(RLIMIT_NOFILE, &rl)) {
138 /* on failure do not abort, only issue a warning */
139 t537_store_errmsg("setrlimit() failed", errno);
140 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
141 t537_msgbuff[0] = '\0';
142 }
143 }
144#endif
146 curl_mfprintf(stderr, "raising soft limit up to hard limit\n");
147 rl.rlim_cur = rl.rlim_max;
148 if(setrlimit(RLIMIT_NOFILE, &rl)) {
149 /* on failure do not abort, only issue a warning */
150 t537_store_errmsg("setrlimit() failed", errno);
151 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
152 t537_msgbuff[0] = '\0';
153 }
155 /* get current open file limits */
157 if(getrlimit(RLIMIT_NOFILE, &rl)) {
158 t537_store_errmsg("getrlimit() failed", errno);
159 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
160 return -3;
161 }
163 /* show current open file limits */
165 tutil_rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
166 curl_mfprintf(stderr, "current soft limit: %s\n", strbuff);
168 tutil_rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
169 curl_mfprintf(stderr, "current hard limit: %s\n", strbuff);
171 } /* (rl.rlim_cur != rl.rlim_max) */
173 /*
174 * test 537 is all about testing libcurl functionality
175 * when the system has nearly exhausted the number of
176 * available file descriptors. Test 537 tries to run
177 * with a small number of file descriptors available.
178 * This implies that any file descriptor which is open
179 * when the test runs does have a number in the high range
180 * of whatever the system supports.
181 */
183 /*
184 * reserve a chunk of memory before opening file descriptors to
185 * avoid a low memory condition once the file descriptors are
186 * open. System conditions that could make the test fail should
187 * be addressed in the precheck phase. This chunk of memory shall
188 * be always curlx_free()ed before exiting the t537_test_rlimit()
189 * function so that it becomes available to the test.
190 */
192 for(nitems = i = 1; nitems <= i; i *= 2)
193 nitems = i;
194 if(nitems > 0x7fff)
195 nitems = 0x40000;
196 do {
197 t537_num_open.rlim_max = sizeof(*memchunk) * nitems;
198 tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max);
199 curl_mfprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
200 memchunk = curlx_malloc(sizeof(*memchunk) * (size_t)nitems);
201 if(!memchunk) {
202 curl_mfprintf(stderr, "memchunk, malloc() failed\n");
203 nitems /= 2;
204 }
205 } while(nitems && !memchunk);
206 if(!memchunk) {
207 t537_store_errmsg("memchunk, malloc() failed", errno);
208 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
209 return -4;
210 }
212 /* initialize it to fight lazy allocation */
214 curl_mfprintf(stderr, "initializing memchunk array\n");
216 for(i = 0; i < nitems; i++)
217 memchunk[i] = -1;
219 /* set the number of file descriptors we try to open */
221#ifdef RLIM_INFINITY
222 if((rl.rlim_cur > 0) && (rl.rlim_cur != RLIM_INFINITY)) {
223#else
224 if(rl.rlim_cur > 0) {
225#endif
226 /* soft limit minus T537_SAFETY_MARGIN */
227 t537_num_open.rlim_max = rl.rlim_cur - T537_SAFETY_MARGIN;
228 }
229 else {
230 /* a huge number of file descriptors */
231 for(nitems = i = 1; nitems <= i; i *= 2)
232 nitems = i;
233 if(nitems > 0x7fff)
234 nitems = 0x40000;
235 t537_num_open.rlim_max = nitems;
236 }
238 /* verify that we do not overflow size_t in curlx_malloc() */
240 if((size_t)t537_num_open.rlim_max > ((size_t)-1) / sizeof(*t537_testfd)) {
241 tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_max);
242 curl_msnprintf(strbuff, sizeof(strbuff),
243 "unable to allocate an array for %s "
244 "file descriptors, would overflow size_t", strbuff1);
245 t537_store_errmsg(strbuff, 0);
246 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
247 curlx_free(memchunk);
248 return -5;
249 }
251 /* allocate array for file descriptors */
253 do {
254 tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max);
255 curl_mfprintf(stderr, "allocating array for %s file descriptors\n",
256 strbuff);
258 t537_testfd = curlx_malloc(sizeof(*t537_testfd) *
259 (size_t)t537_num_open.rlim_max);
260 if(!t537_testfd) {
261 curl_mfprintf(stderr, "testfd, malloc() failed\n");
262 t537_num_open.rlim_max /= 2;
263 }
264 } while(t537_num_open.rlim_max && !t537_testfd);
265 if(!t537_testfd) {
266 t537_store_errmsg("testfd, malloc() failed", errno);
267 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
268 curlx_free(memchunk);
269 return -6;
270 }
272 /* initialize it to fight lazy allocation */
274 curl_mfprintf(stderr, "initializing testfd array\n");
276 for(t537_num_open.rlim_cur = 0;
277 t537_num_open.rlim_cur < t537_num_open.rlim_max;
278 t537_num_open.rlim_cur++)
279 t537_testfd[t537_num_open.rlim_cur] = -1;
281 tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max);
282 curl_mfprintf(stderr, "trying to open %s file descriptors\n", strbuff);
284 /* open a dummy descriptor */
286 t537_testfd[0] = curlx_open(DEV_NULL, O_RDONLY);
287 if(t537_testfd[0] < 0) {
288 curl_msnprintf(strbuff, sizeof(strbuff), "opening of %s failed", DEV_NULL);
289 t537_store_errmsg(strbuff, errno);
290 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
291 curlx_safefree(t537_testfd);
292 curlx_free(memchunk);
293 return -7;
294 }
296 /* create a bunch of file descriptors */
298 for(t537_num_open.rlim_cur = 1;
299 t537_num_open.rlim_cur < t537_num_open.rlim_max;
300 t537_num_open.rlim_cur++) {
302 t537_testfd[t537_num_open.rlim_cur] = dup(t537_testfd[0]);
304 if(t537_testfd[t537_num_open.rlim_cur] < 0) {
306 t537_testfd[t537_num_open.rlim_cur] = -1;
308 tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_cur);
309 curl_msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed",
310 strbuff1);
311 curl_mfprintf(stderr, "%s\n", strbuff);
313 tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_cur);
314 curl_msnprintf(strbuff, sizeof(strbuff),
315 "fds system limit seems close to %s", strbuff1);
316 curl_mfprintf(stderr, "%s\n", strbuff);
318 t537_num_open.rlim_max = t537_num_open.rlim_cur - T537_SAFETY_MARGIN;
320 t537_num_open.rlim_cur -= t537_num_open.rlim_max;
321 tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_cur);
322 curl_msnprintf(strbuff, sizeof(strbuff), "closing %s file descriptors",
323 strbuff1);
324 curl_mfprintf(stderr, "%s\n", strbuff);
326 for(t537_num_open.rlim_cur = t537_num_open.rlim_max;
327 t537_testfd[t537_num_open.rlim_cur] >= 0;
328 t537_num_open.rlim_cur++) {
329 curlx_close(t537_testfd[t537_num_open.rlim_cur]);
330 t537_testfd[t537_num_open.rlim_cur] = -1;
331 }
333 tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max);
334 curl_mfprintf(stderr, "shrinking array for %s file descriptors\n",
335 strbuff);
337 /* we do not care if we cannot shrink it */
339 tmpfd = curlx_realloc(t537_testfd,
340 sizeof(*t537_testfd) *
341 (size_t)t537_num_open.rlim_max);
342 if(tmpfd) {
343 t537_testfd = tmpfd;
344 tmpfd = NULL;
345 }
347 break;
348 }
349 }
351 tutil_rlim2str(strbuff, sizeof(strbuff), t537_num_open.rlim_max);
352 curl_mfprintf(stderr, "%s file descriptors open\n", strbuff);
354#if !defined(HAVE_POLL) && !defined(USE_WINSOCK)
355 /*
356 * when using select() instead of poll() we cannot test
357 * libcurl functionality with a socket number equal or
358 * greater than FD_SETSIZE. In any case, macro VERIFY_SOCK
359 * in lib/select.c enforces this check and protects libcurl
360 * from a possible crash. The effect of this protection
361 * is that test 537 always fails, since the actual
362 * call to select() never takes place. We skip test 537
363 * with an indication that select limit would be exceeded.
364 */
366 t537_num_open.rlim_cur = FD_SETSIZE - T537_SAFETY_MARGIN;
367 if(t537_num_open.rlim_max > t537_num_open.rlim_cur) {
368 curl_msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
369 FD_SETSIZE);
370 t537_store_errmsg(strbuff, 0);
371 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
372 t537_close_file_descriptors();
373 curlx_free(memchunk);
374 return -8;
375 }
377 t537_num_open.rlim_cur = FD_SETSIZE - T537_SAFETY_MARGIN;
378 for(rl.rlim_cur = 0;
379 rl.rlim_cur < t537_num_open.rlim_max;
380 rl.rlim_cur++) {
381 if((t537_testfd[rl.rlim_cur] > 0) &&
382 ((unsigned int)t537_testfd[rl.rlim_cur] > t537_num_open.rlim_cur)) {
383 curl_msnprintf(strbuff, sizeof(strbuff), "select limit is FD_SETSIZE %d",
384 FD_SETSIZE);
385 t537_store_errmsg(strbuff, 0);
386 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
387 t537_close_file_descriptors();
388 curlx_free(memchunk);
389 return -9;
390 }
391 }
392#endif /* !HAVE_POLL && !USE_WINSOCK */
394 /*
395 * Old or 'backwards compatible' implementations of stdio do not allow
396 * handling of streams with an underlying file descriptor number greater
397 * than 255, even when allowing high numbered file descriptors for sockets.
398 * At this point we have a big number of file descriptors which have been
399 * opened using dup(), so lets test the stdio implementation and discover
400 * if it is capable of fopen()ing some additional files.
401 */
403 if(!t537_fopen_works()) {
404 tutil_rlim2str(strbuff1, sizeof(strbuff1), t537_num_open.rlim_max);
405 curl_msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open",
406 strbuff1);
407 curl_mfprintf(stderr, "%s\n", t537_msgbuff);
408 curl_msnprintf(strbuff, sizeof(strbuff),
409 "fopen fails with lots of fds open");
410 t537_store_errmsg(strbuff, 0);
411 t537_close_file_descriptors();
412 curlx_free(memchunk);
413 return -10;
414 }
416 /* free the chunk of memory we were reserving so that it
417 becomes available to the test */
419 curlx_free(memchunk);
421 /* close file descriptors unless instructed to keep them */
423 if(!keep_open) {
424 t537_close_file_descriptors();
425 }
427 return 0;
430static CURLcode test_lib537(const char *URL)
432 CURLcode result;
433 CURL *curl;
435 if(!strcmp(URL, "check")) {
436 /* used by the test script to ask if we can run this test or not */
437 if(t537_test_rlimit(FALSE)) {
438 curl_mfprintf(stdout, "test_rlimit problem: %s\n", t537_msgbuff);
439 return TEST_ERR_FAILURE;
440 }
441 return CURLE_OK; /* sure, run this! */
442 }
444 if(t537_test_rlimit(TRUE)) {
445 /* failure */
446 return TEST_ERR_MAJOR_BAD;
447 }
449 /* run the test with the bunch of open file descriptors
450 and close them all once the test is over */
452 if(curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
453 curl_mfprintf(stderr, "curl_global_init() failed\n");
454 t537_close_file_descriptors();
455 return TEST_ERR_MAJOR_BAD;
456 }
458 curl = curl_easy_init();
459 if(!curl) {
460 curl_mfprintf(stderr, "curl_easy_init() failed\n");
461 t537_close_file_descriptors();
462 curl_global_cleanup();
463 return TEST_ERR_MAJOR_BAD;
464 }
466 easy_setopt(curl, CURLOPT_URL, URL);
467 easy_setopt(curl, CURLOPT_HEADER, 1L);
469 result = curl_easy_perform(curl);
471test_cleanup:
473 t537_close_file_descriptors();
474 curl_easy_cleanup(curl);
475 curl_global_cleanup();
477 return result;
480#else /* HAVE_GETRLIMIT && HAVE_SETRLIMIT */
482static CURLcode test_lib537(const char *URL)
484 (void)URL;
485 curl_mprintf("system lacks necessary system function(s)");
486 return TEST_ERR_MAJOR_BAD; /* skip test */
489#endif /* HAVE_GETRLIMIT && HAVE_SETRLIMIT */
Diagnostics4 git calls · 1.0 s
CallStatusSizeTime01.0 s
discover200152 B1 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=1
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 · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
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 · hit3 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=3
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=86
Open pack map
fetch2004.4 KiB1.0 s
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=1033
git.response.bytes=4548
git.response.cache=MISS
git.response.duration_ms=1033
git.fetch.wants=ab19316b0dd56d5addedc64a2a6c8660d125e5b6
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=4548
git.pkt.payload.max=4527
git.sideband.band1.bytes=4526
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
a5e33b3649b5f162
Request
66c25a59…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format