Artifactspublic-v0

ply

main
ply4 git calls313 ms40 KiB1 cachedprotocol v2
108 lines7.1 KiBRaw
1// Upload progress on a real socket (#255): the platform's own fetch (undici) to a node:http server, no double.
2// What ply can hold a limit to is what it can see: the platform pulling a piece of the request body. These tests pin
3// that granularity (pieces of at most 64 KiB, however large the source chunk) and which limit names which stall.
4// They assert counts and limit names, never elapsed time; the timeouts are far from what a loaded machine reaches.
5import { test } from 'vitest';
6import assert from 'node:assert/strict';
7import http from 'node:http';
8import { createTransport } from '../src/http.js';
9import { withLimits } from '../src/limits.js';
11const RP = { 'content-type': 'application/x-git-receive-pack-result' };
12const MIB = 1 << 20;
13const spanOf = () => ({ set() {}, event() {}, error() {} });
14const serve = handler => new Promise(resolve => {
15 const s = http.createServer(handler);
16 s.listen(0, '127.0.0.1', () => resolve({ url: `http://127.0.0.1:${s.address().port}/r`, close: () => { s.closeAllConnections(); s.close(); } }));
17});
18// The platform's fetch, recording every piece it pulls from the request body and how much the server had read by then.
19// The recorder has no buffer of its own (highWaterMark 0), so a recorded pull is a pull by the platform.
20const observed = (pieces, serverRead) => (url, init) => {
21 if (!(init.body instanceof ReadableStream)) return fetch(url, init);
22 const rd = init.body.getReader();
23 const body = new ReadableStream({
24 async pull(c) { const r = await rd.read(); if (r.done) { c.close(); return; } pieces.push({ bytes: r.value.length, serverRead: serverRead() }); c.enqueue(r.value); },
25 cancel: reason => rd.cancel(reason),
26 }, { highWaterMark: 0 });
27 return fetch(url, { ...init, body });
28};
29// a source of `count` chunks of `size` bytes, read only when pulled; `pulls.n` counts the chunks taken
30const source = (count, size, pulls) => {
31 const chunk = new Uint8Array(size);
32 return { stream: new ReadableStream({ pull(c) { if (pulls.n === count) { c.close(); return; } pulls.n++; c.enqueue(chunk); } }, { highWaterMark: 0 }), length: count * size };
33};
34// the outcome of the exchange, never a rejection
35const push = async (t, body) => {
36 let frames = 0;
37 try { for await (const _ of t.frames('git-receive-pack', body, spanOf(), { bypassCache: false })) frames++; } catch (error) { return { frames, code: error.code, what: error.what }; }
38 return { frames };
39};
41test('one 4 MiB chunk to a server that reads 64 KiB per 25 ms: the platform takes it in 64 pieces and it is answered', async () => {
42 // The finding's experiment. 4 MiB / 64 KiB = 64 pieces, each a progress mark; before the split the platform took the
43 // chunk in one pull, so the clock saw one mark and then nothing until the whole 4 MiB had left undici's queue.
44 const seen = { bytes: 0 };
45 const srv = await serve((req, res) => {
46 req.on('data', d => { seen.bytes += d.length; req.pause(); setTimeout(() => { req.resume(); }, 25); });
47 req.on('end', () => { res.writeHead(200, RP); res.end('0000'); });
48 req.on('error', () => { /* the client went away */ });
49 });
50 const pieces = [];
51 const pulls = { n: 0 };
52 try {
53 const t = createTransport(srv.url, { fetchImpl: observed(pieces, () => seen.bytes), limits: withLimits({ firstByteTimeoutMs: 30_000, idleTimeoutMs: 10_000 }) }).value;
54 const r = await push(t, source(1, 4 * MIB, pulls));
55 assert.deepEqual(r, { frames: 1 });
56 assert.equal(seen.bytes, 4 * MIB);
57 assert.deepEqual([pieces.length, Math.max(...pieces.map(p => p.bytes)), pieces.reduce((n, p) => n + p.bytes, 0)], [64, 65_536, 4 * MIB]);
58 } finally { srv.close(); }
59}, 60_000);
61test('pieces remain and the platform takes no more (the server stopped reading): the limit that fires is idleTimeoutMs', async () => {
62 // 64 MiB in 1 MiB chunks, more than undici's queue and the kernel's socket buffers hold, to a server that reads once
63 // and never again. The platform stops pulling, so the source is never read to its end (pulls < 64) and the upload
64 // has not ended: the limit is the idle one, whatever the first-byte limit is.
65 const srv = await serve(req => { req.once('data', () => { req.pause(); }); req.on('error', () => { /* cut */ }); });
66 const pieces = [];
67 const pulls = { n: 0 };
68 try {
69 const t = createTransport(srv.url, { fetchImpl: observed(pieces, () => 0), limits: withLimits({ firstByteTimeoutMs: 30_000, idleTimeoutMs: 300 }) }).value;
70 const r = await push(t, source(64, MIB, pulls));
71 assert.deepEqual(r, { frames: 0, code: 'timeout', what: 'idleTimeoutMs' });
72 assert.ok(pulls.n < 64, `the source was read to its end (${pulls.n} chunks): the upload did not stall`);
73 } finally { srv.close(); }
74}, 60_000);
76test('with the idle and first-byte limits off, requestTimeoutMs ends an upload the server never reads, whatever the platform buffered', async () => {
77 // README Limits: requestTimeoutMs caps the whole exchange, body included. So it is the bound whether the platform
78 // still has pieces to take (64 MiB, more than its buffers hold: the source is not read to its end) or has taken
79 // them all (one 64 KiB piece, buffered whole and never read by the server).
80 const srv = await serve(req => { req.on('error', () => { /* cut */ }); });
81 const limits = withLimits({ firstByteTimeoutMs: 0, idleTimeoutMs: 0, requestTimeoutMs: 300 });
82 try {
83 const large = { pieces: [], pulls: { n: 0 } };
84 const r1 = await push(createTransport(srv.url, { fetchImpl: observed(large.pieces, () => 0), limits }).value, source(64, MIB, large.pulls));
85 assert.deepEqual(r1, { frames: 0, code: 'timeout', what: 'requestTimeoutMs' });
86 assert.ok(large.pulls.n < 64, `the source was read to its end (${large.pulls.n} chunks): the upload did not stall`);
87 const small = { pieces: [], pulls: { n: 0 } };
88 // This case asserts that the platform took the piece before the limit fired, so its limit is seconds, not 300 ms:
89 // the first pull was measured at most 10 ms after the request began on a loaded machine.
90 const seconds = withLimits({ firstByteTimeoutMs: 0, idleTimeoutMs: 0, requestTimeoutMs: 5_000 });
91 const r2 = await push(createTransport(srv.url, { fetchImpl: observed(small.pieces, () => 0), limits: seconds }).value, source(1, 65_536, small.pulls));
92 assert.deepEqual(r2, { frames: 0, code: 'timeout', what: 'requestTimeoutMs' });
93 assert.deepEqual(small.pieces.map(p => p.bytes), [65_536]);
94 } finally { srv.close(); }
95}, 60_000);
97test('a server that reads the whole upload and never answers is firstByteTimeoutMs: every piece was handed over', async () => {
98 const seen = { bytes: 0 };
99 const srv = await serve(req => { req.on('data', d => { seen.bytes += d.length; }); req.on('error', () => { /* cut */ }); });
100 const pieces = [];
101 const pulls = { n: 0 };
102 try {
103 const t = createTransport(srv.url, { fetchImpl: observed(pieces, () => seen.bytes), limits: withLimits({ firstByteTimeoutMs: 300, idleTimeoutMs: 30_000 }) }).value;
104 const r = await push(t, source(1, 4 * MIB, pulls));
105 assert.deepEqual(r, { frames: 0, code: 'timeout', what: 'firstByteTimeoutMs' });
106 assert.equal(pieces.length, 64);
107 } finally { srv.close(); }
108}, 60_000);
Diagnostics4 git calls · 313 ms
CallStatusSizeTime0313 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-refs200145 B3 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=145
git.response.cache=UPDATING
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=145
git.pkt.payload.max=76
git.ls_refs.count=2
git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020038 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=38434
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=19912563f540228593df0c489082e5e2508e21e4
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=6
git.pkt.data=4
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=38434
git.pkt.payload.max=38339
git.sideband.band1.bytes=38338
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=63
git.pack.bytes=38338
git.pack.ofs_delta=0
git.pack.ref_delta=8
git.pack.chain.max=8
git.pack.trailer=0bc36ab7adf82d3109177f11f1ea93f1ce071f77
git.pack.full=55
Open pack map
fetch2002.4 KiB308 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=308
git.response.bytes=2479
git.response.cache=MISS
git.response.duration_ms=308
git.fetch.wants=f91d09341e7cbf765ca75ecc2ac19494cf9d4025
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=2479
git.pkt.payload.max=2458
git.sideband.band1.bytes=2457
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/ply.git
Ref
refs/heads/main
Commit
19912563f540228593df0c489082e5e2508e21e4
cf-ray
a5e202044a8c70b8
Request
2c12a68d…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format