@indigoai-us/hq-cloud 6.18.1-alpha.6 → 6.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bandwidth.d.ts +11 -45
- package/dist/bandwidth.d.ts.map +1 -1
- package/dist/bandwidth.js +18 -231
- package/dist/bandwidth.js.map +1 -1
- package/dist/bandwidth.test.js +4 -124
- package/dist/bandwidth.test.js.map +1 -1
- package/dist/bin/sync-runner-company.d.ts +0 -2
- package/dist/bin/sync-runner-company.d.ts.map +1 -1
- package/dist/bin/sync-runner-company.js +0 -6
- package/dist/bin/sync-runner-company.js.map +1 -1
- package/dist/bin/sync-runner-manifest.d.ts +2 -0
- package/dist/bin/sync-runner-manifest.d.ts.map +1 -1
- package/dist/bin/sync-runner-manifest.js +439 -1
- package/dist/bin/sync-runner-manifest.js.map +1 -1
- package/dist/bin/sync-runner-manifest.test.js +374 -16
- package/dist/bin/sync-runner-manifest.test.js.map +1 -1
- package/dist/bin/sync-runner-watch-loop.d.ts +1 -26
- package/dist/bin/sync-runner-watch-loop.d.ts.map +1 -1
- package/dist/bin/sync-runner-watch-loop.js +3 -217
- package/dist/bin/sync-runner-watch-loop.js.map +1 -1
- package/dist/bin/sync-runner.d.ts +2 -26
- package/dist/bin/sync-runner.d.ts.map +1 -1
- package/dist/bin/sync-runner.js +5 -14
- package/dist/bin/sync-runner.js.map +1 -1
- package/dist/bin/sync-runner.test.js +1 -107
- package/dist/bin/sync-runner.test.js.map +1 -1
- package/dist/cli/share.d.ts +6 -18
- package/dist/cli/share.d.ts.map +1 -1
- package/dist/cli/share.js +47 -92
- package/dist/cli/share.js.map +1 -1
- package/dist/cli/share.test.js +3 -3
- package/dist/cli/share.test.js.map +1 -1
- package/dist/cli/sync.d.ts +4 -17
- package/dist/cli/sync.d.ts.map +1 -1
- package/dist/cli/sync.js +27 -155
- package/dist/cli/sync.js.map +1 -1
- package/dist/cli/sync.test.js +1 -315
- package/dist/cli/sync.test.js.map +1 -1
- package/dist/manifest/upload-manifest.d.ts +6 -0
- package/dist/manifest/upload-manifest.d.ts.map +1 -1
- package/dist/manifest/upload-manifest.js +18 -3
- package/dist/manifest/upload-manifest.js.map +1 -1
- package/dist/object-io.d.ts +7 -33
- package/dist/object-io.d.ts.map +1 -1
- package/dist/object-io.js +140 -326
- package/dist/object-io.js.map +1 -1
- package/dist/object-io.test.js +1 -377
- package/dist/object-io.test.js.map +1 -1
- package/dist/s3.d.ts +3 -8
- package/dist/s3.d.ts.map +1 -1
- package/dist/s3.js +27 -304
- package/dist/s3.js.map +1 -1
- package/dist/s3.test.js +0 -163
- package/dist/s3.test.js.map +1 -1
- package/dist/sync/inbound-event-admission.d.ts.map +1 -1
- package/dist/sync/inbound-event-admission.js +0 -3
- package/dist/sync/inbound-event-admission.js.map +1 -1
- package/dist/sync/inbound-event-admission.test.js +0 -6
- package/dist/sync/inbound-event-admission.test.js.map +1 -1
- package/dist/sync/push-receiver.d.ts.map +1 -1
- package/dist/sync/push-receiver.js +1 -30
- package/dist/sync/push-receiver.js.map +1 -1
- package/dist/sync/push-receiver.test.js +0 -97
- package/dist/sync/push-receiver.test.js.map +1 -1
- package/dist/sync-core.d.ts +1 -2
- package/dist/sync-core.d.ts.map +1 -1
- package/dist/sync-core.js +10 -5
- package/dist/sync-core.js.map +1 -1
- package/dist/sync-core.test.js +0 -16
- package/dist/sync-core.test.js.map +1 -1
- package/package.json +1 -1
- package/dist/s3-download-stream-hash.test.d.ts +0 -2
- package/dist/s3-download-stream-hash.test.d.ts.map +0 -1
- package/dist/s3-download-stream-hash.test.js +0 -70
- package/dist/s3-download-stream-hash.test.js.map +0 -1
package/dist/object-io.js
CHANGED
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
import { S3Client, PutObjectCommand, GetObjectCommand, ListObjectsV2Command, DeleteObjectCommand, HeadObjectCommand, } from "@aws-sdk/client-s3";
|
|
26
26
|
import * as http from "node:http";
|
|
27
27
|
import * as https from "node:https";
|
|
28
|
-
import { Transform } from "node:stream";
|
|
29
28
|
import { isAbortOrTimeoutError, isTransientNetworkError } from "./lib/net-errors.js";
|
|
30
29
|
import { headersForObjectLockPut, isObjectLockChecksumRequiredBody, isObjectLockChecksumRequiredError, ObjectLockChecksumRequiredError, } from "./lib/s3-content-checksum.js";
|
|
31
30
|
export { ObjectLockChecksumRequiredError };
|
|
@@ -37,97 +36,13 @@ import { VaultClientError } from "./vault-client.js";
|
|
|
37
36
|
* socket fails the leg as transient instead of freezing the runner.
|
|
38
37
|
*/
|
|
39
38
|
export const OBJECT_IO_REQUEST_TIMEOUT_MS = 60_000;
|
|
40
|
-
/** Maximum idle interval while consuming one streamed object body. */
|
|
41
|
-
export const OBJECT_IO_BODY_IDLE_TIMEOUT_MS = 15_000;
|
|
42
39
|
let objectIORequestTimeoutMsForTest;
|
|
43
|
-
let objectIOBodyIdleTimeoutMsForTest;
|
|
44
40
|
export function objectIORequestTimeoutMs() {
|
|
45
41
|
return objectIORequestTimeoutMsForTest ?? OBJECT_IO_REQUEST_TIMEOUT_MS;
|
|
46
42
|
}
|
|
47
43
|
export function setObjectIORequestTimeoutMsForTesting(ms) {
|
|
48
44
|
objectIORequestTimeoutMsForTest = ms;
|
|
49
45
|
}
|
|
50
|
-
export function setObjectIOBodyIdleTimeoutMsForTesting(ms) {
|
|
51
|
-
objectIOBodyIdleTimeoutMsForTest = ms;
|
|
52
|
-
}
|
|
53
|
-
function objectIOBodyIdleTimeoutMs() {
|
|
54
|
-
return objectIOBodyIdleTimeoutMsForTest ?? OBJECT_IO_BODY_IDLE_TIMEOUT_MS;
|
|
55
|
-
}
|
|
56
|
-
export class ObjectBodyIdleTimeoutError extends Error {
|
|
57
|
-
constructor(key, timeoutMs) {
|
|
58
|
-
super(`object body made no progress for ${timeoutMs} ms: ${key}`);
|
|
59
|
-
this.name = "ObjectBodyIdleTimeoutError";
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/** Bound a streamed GET after response headers arrive. */
|
|
63
|
-
export async function* withObjectBodyIdleTimeout(body, key, timeoutMs = objectIOBodyIdleTimeoutMs(), onTimeout) {
|
|
64
|
-
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
|
|
65
|
-
throw new Error("object body idle timeout must be positive");
|
|
66
|
-
}
|
|
67
|
-
const iterator = body[Symbol.asyncIterator]();
|
|
68
|
-
let complete = false;
|
|
69
|
-
let closed = false;
|
|
70
|
-
const close = () => {
|
|
71
|
-
if (closed)
|
|
72
|
-
return;
|
|
73
|
-
closed = true;
|
|
74
|
-
try {
|
|
75
|
-
void Promise.resolve(iterator.return?.()).catch(() => undefined);
|
|
76
|
-
}
|
|
77
|
-
catch {
|
|
78
|
-
// Preserve the timeout/error as the authoritative transfer result.
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
try {
|
|
82
|
-
while (true) {
|
|
83
|
-
let timer;
|
|
84
|
-
const item = await Promise.race([
|
|
85
|
-
Promise.resolve(iterator.next()),
|
|
86
|
-
new Promise((_resolve, reject) => {
|
|
87
|
-
timer = setTimeout(() => {
|
|
88
|
-
const error = new ObjectBodyIdleTimeoutError(key, timeoutMs);
|
|
89
|
-
try {
|
|
90
|
-
onTimeout?.(error);
|
|
91
|
-
}
|
|
92
|
-
catch {
|
|
93
|
-
// Preserve the timeout/error as the authoritative transfer result.
|
|
94
|
-
}
|
|
95
|
-
close();
|
|
96
|
-
reject(error);
|
|
97
|
-
}, timeoutMs);
|
|
98
|
-
}),
|
|
99
|
-
]).finally(() => {
|
|
100
|
-
if (timer !== undefined)
|
|
101
|
-
clearTimeout(timer);
|
|
102
|
-
});
|
|
103
|
-
if (item.done) {
|
|
104
|
-
complete = true;
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
yield item.value;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
finally {
|
|
111
|
-
if (!complete)
|
|
112
|
-
close();
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
function cancelObjectBody(body, error) {
|
|
116
|
-
if (!body || typeof body !== "object")
|
|
117
|
-
return;
|
|
118
|
-
const stream = body;
|
|
119
|
-
try {
|
|
120
|
-
if (typeof stream.destroy === "function") {
|
|
121
|
-
stream.destroy(error);
|
|
122
|
-
}
|
|
123
|
-
else if (typeof stream.cancel === "function") {
|
|
124
|
-
void Promise.resolve(stream.cancel(error)).catch(() => undefined);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
catch {
|
|
128
|
-
// The idle timeout remains the authoritative transfer failure.
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
46
|
function objectIOAbortSignal() {
|
|
132
47
|
return AbortSignal.timeout(objectIORequestTimeoutMs());
|
|
133
48
|
}
|
|
@@ -327,19 +242,11 @@ export class S3SdkObjectIO {
|
|
|
327
242
|
}
|
|
328
243
|
}
|
|
329
244
|
async putObject(input) {
|
|
330
|
-
if (input.bypassBandwidthGovernor)
|
|
331
|
-
return this.putObjectWithGovernor(input);
|
|
332
|
-
return getBandwidthGovernor().withChoreTransfer(() => this.putObjectWithGovernor(input));
|
|
333
|
-
}
|
|
334
|
-
async putObjectWithGovernor(input) {
|
|
335
|
-
const governor = getBandwidthGovernor();
|
|
336
245
|
// Data-plane pacing: acquire tokens for the whole body before the PUT so
|
|
337
246
|
// aggregate upload+download throughput stays under the governor's cap.
|
|
338
|
-
|
|
339
|
-
await governor.acquire(input.body.byteLength);
|
|
340
|
-
}
|
|
247
|
+
await getBandwidthGovernor().acquire(input.body.byteLength);
|
|
341
248
|
try {
|
|
342
|
-
const
|
|
249
|
+
const res = await this.sendWithCredentialRetry((client, abortSignal) => client.send(new PutObjectCommand({
|
|
343
250
|
Bucket: this.bucket,
|
|
344
251
|
Key: input.key,
|
|
345
252
|
Body: input.body,
|
|
@@ -356,9 +263,6 @@ export class S3SdkObjectIO {
|
|
|
356
263
|
...(input.ifMatch ? { IfMatch: quoteEtag(input.ifMatch) } : {}),
|
|
357
264
|
...(input.ifNoneMatch ? { IfNoneMatch: input.ifNoneMatch } : {}),
|
|
358
265
|
}), { abortSignal }));
|
|
359
|
-
const res = input.bypassBandwidthGovernor
|
|
360
|
-
? await send()
|
|
361
|
-
: await governor.measureRawTransfer(input.body.byteLength, send);
|
|
362
266
|
return { etag: res.ETag || "" };
|
|
363
267
|
}
|
|
364
268
|
catch (err) {
|
|
@@ -368,51 +272,20 @@ export class S3SdkObjectIO {
|
|
|
368
272
|
throw err;
|
|
369
273
|
}
|
|
370
274
|
}
|
|
371
|
-
async getObjectStream(key
|
|
372
|
-
const
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
: await governor.reserveChoreTransfer();
|
|
376
|
-
try {
|
|
377
|
-
const res = await this.sendWithCredentialRetry((client, abortSignal) => client.send(new GetObjectCommand({
|
|
378
|
-
Bucket: this.bucket,
|
|
379
|
-
Key: key,
|
|
380
|
-
...(options.rangeStart !== undefined
|
|
381
|
-
? { Range: `bytes=${options.rangeStart}-` }
|
|
382
|
-
: {}),
|
|
383
|
-
...(options.ifMatch ? { IfMatch: quoteEtag(options.ifMatch) } : {}),
|
|
384
|
-
}), { abortSignal }));
|
|
385
|
-
if (!res.Body) {
|
|
386
|
-
throw new Error(`Empty response for ${key}`);
|
|
387
|
-
}
|
|
388
|
-
const rawBody = res.Body;
|
|
389
|
-
const observedBody = options.bypassBandwidthGovernor
|
|
390
|
-
? rawBody
|
|
391
|
-
: governor.observeRawBody(rawBody);
|
|
392
|
-
const idleBoundBody = withObjectBodyIdleTimeout(observedBody, key, objectIOBodyIdleTimeoutMs(), (error) => cancelObjectBody(res.Body, error));
|
|
393
|
-
return {
|
|
394
|
-
body: options.bypassBandwidthGovernor
|
|
395
|
-
? idleBoundBody
|
|
396
|
-
: governor.governBody(idleBoundBody, release),
|
|
397
|
-
metadata: res.Metadata,
|
|
398
|
-
etag: res.ETag,
|
|
399
|
-
versionId: res.VersionId,
|
|
400
|
-
contentLength: res.ContentLength,
|
|
401
|
-
contentRange: res.ContentRange,
|
|
402
|
-
statusCode: res.$metadata?.httpStatusCode,
|
|
403
|
-
destroy: (error) => {
|
|
404
|
-
cancelObjectBody(res.Body, error ?? new Error(`GET body closed: ${key}`));
|
|
405
|
-
release?.();
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
catch (error) {
|
|
410
|
-
release?.();
|
|
411
|
-
throw error;
|
|
275
|
+
async getObjectStream(key) {
|
|
276
|
+
const res = await this.sendWithCredentialRetry((client, abortSignal) => client.send(new GetObjectCommand({ Bucket: this.bucket, Key: key }), { abortSignal }));
|
|
277
|
+
if (!res.Body) {
|
|
278
|
+
throw new Error(`Empty response for ${key}`);
|
|
412
279
|
}
|
|
280
|
+
return {
|
|
281
|
+
// Data-plane pacing: each chunk acquires governor tokens before it is
|
|
282
|
+
// yielded (backpressure — the SDK stream pauses while we wait).
|
|
283
|
+
body: getBandwidthGovernor().throttleBody(res.Body),
|
|
284
|
+
metadata: res.Metadata,
|
|
285
|
+
};
|
|
413
286
|
}
|
|
414
|
-
async getObject(key
|
|
415
|
-
const res = await this.getObjectStream(key
|
|
287
|
+
async getObject(key) {
|
|
288
|
+
const res = await this.getObjectStream(key);
|
|
416
289
|
const body = await drainToBuffer(res.body);
|
|
417
290
|
return { body, metadata: res.metadata };
|
|
418
291
|
}
|
|
@@ -449,7 +322,6 @@ export class S3SdkObjectIO {
|
|
|
449
322
|
lastModified: res.LastModified || new Date(),
|
|
450
323
|
etag: res.ETag || "",
|
|
451
324
|
size: res.ContentLength || 0,
|
|
452
|
-
versionId: res.VersionId,
|
|
453
325
|
metadata: res.Metadata,
|
|
454
326
|
storageClass: res.StorageClass ?? "STANDARD",
|
|
455
327
|
};
|
|
@@ -508,41 +380,39 @@ function expectedContentLength(headers) {
|
|
|
508
380
|
function contentLengthError(expected, actual) {
|
|
509
381
|
return Object.assign(new Error(`presigned GET content-length mismatch: expected ${expected} bytes, received ${actual}`), { code: "ERR_HQ_TRUNCATED_RESPONSE" });
|
|
510
382
|
}
|
|
511
|
-
function checkedNodeBody(message, expected) {
|
|
383
|
+
async function* checkedNodeBody(message, expected) {
|
|
512
384
|
let received = 0;
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
385
|
+
let exhausted = false;
|
|
386
|
+
try {
|
|
387
|
+
try {
|
|
388
|
+
for await (const chunk of message) {
|
|
389
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
390
|
+
received += bytes.byteLength;
|
|
391
|
+
if (expected !== undefined && received > expected) {
|
|
392
|
+
throw contentLengthError(expected, received);
|
|
393
|
+
}
|
|
394
|
+
yield bytes;
|
|
519
395
|
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
396
|
+
}
|
|
397
|
+
catch (err) {
|
|
398
|
+
// A FIN before Node has received the declared bytes normally surfaces as
|
|
399
|
+
// an "aborted" stream error. Preserve the useful data-integrity cause.
|
|
523
400
|
if (expected !== undefined && received !== expected) {
|
|
524
|
-
|
|
525
|
-
return;
|
|
401
|
+
throw contentLengthError(expected, received);
|
|
526
402
|
}
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
: new Error("presigned GET body aborted"));
|
|
539
|
-
});
|
|
540
|
-
body.once("close", () => {
|
|
541
|
-
if (!message.destroyed)
|
|
403
|
+
throw err;
|
|
404
|
+
}
|
|
405
|
+
exhausted = true;
|
|
406
|
+
if (expected !== undefined && received !== expected) {
|
|
407
|
+
throw contentLengthError(expected, received);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
// Consumers such as HEAD only inspect headers, and a caller can stop after
|
|
412
|
+
// a prefix. Destroying in both cases releases the socket immediately.
|
|
413
|
+
if (!exhausted)
|
|
542
414
|
message.destroy();
|
|
543
|
-
}
|
|
544
|
-
message.pipe(body);
|
|
545
|
-
return body;
|
|
415
|
+
}
|
|
546
416
|
}
|
|
547
417
|
function nodePresignedGet(url, headers) {
|
|
548
418
|
const target = new URL(url);
|
|
@@ -558,15 +428,11 @@ function nodePresignedGet(url, headers) {
|
|
|
558
428
|
reject(err);
|
|
559
429
|
return;
|
|
560
430
|
}
|
|
561
|
-
const body = checkedNodeBody(message, expected);
|
|
562
431
|
resolve({
|
|
563
432
|
status: message.statusCode ?? 0,
|
|
564
433
|
headers: responseHeaders,
|
|
565
|
-
body,
|
|
566
|
-
destroy: (
|
|
567
|
-
body.destroy(error);
|
|
568
|
-
message.destroy(error);
|
|
569
|
-
},
|
|
434
|
+
body: checkedNodeBody(message, expected),
|
|
435
|
+
destroy: () => message.destroy(),
|
|
570
436
|
});
|
|
571
437
|
};
|
|
572
438
|
const request = target.protocol === "https:"
|
|
@@ -1041,46 +907,33 @@ export class PresignObjectIO {
|
|
|
1041
907
|
if (isPresignFenceStrictEnabled()) {
|
|
1042
908
|
this.requireSignedPutPreconditions(input.key, input, row.headers);
|
|
1043
909
|
}
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
910
|
+
// Data-plane pacing: acquire tokens for the whole body before the PUT so
|
|
911
|
+
// aggregate upload+download throughput stays under the governor's cap.
|
|
912
|
+
await getBandwidthGovernor().acquire(input.body.byteLength);
|
|
913
|
+
// The server signs Content-Type, SSE-KMS, and every x-amz-meta-* into the
|
|
914
|
+
// signature and returns them in `headers`; they MUST be replayed verbatim
|
|
915
|
+
// or SigV4 rejects the PUT.
|
|
916
|
+
const res = await fetchWithRetry(row.url, {
|
|
917
|
+
method: "PUT",
|
|
918
|
+
body: input.body,
|
|
919
|
+
headers: headersForObjectLockPut(row.url, row.headers, input.body),
|
|
920
|
+
}, `presigned PUT ${input.key}`);
|
|
921
|
+
if (res.status === 412) {
|
|
922
|
+
// The signed conditional header fenced this write off: the remote
|
|
923
|
+
// moved past our baseline (If-Match) or the key already exists
|
|
924
|
+
// (If-None-Match). Same shape as the SDK's PreconditionFailed so the
|
|
925
|
+
// push path routes both transports through one conflict handler.
|
|
926
|
+
const detail = await safeText(res);
|
|
927
|
+
throw preconditionFailedError(input.key, detail);
|
|
928
|
+
}
|
|
929
|
+
if (!res.ok) {
|
|
930
|
+
const detail = await safeText(res);
|
|
931
|
+
if (isObjectLockChecksumRequiredBody(res.status, detail)) {
|
|
932
|
+
throw new ObjectLockChecksumRequiredError(input.key, detail);
|
|
1050
933
|
}
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
// or SigV4 rejects the PUT.
|
|
1055
|
-
const res = await fetchWithRetry(row.url, {
|
|
1056
|
-
method: "PUT",
|
|
1057
|
-
body: input.body,
|
|
1058
|
-
headers: headersForObjectLockPut(row.url, row.headers, input.body),
|
|
1059
|
-
}, `presigned PUT ${input.key}`);
|
|
1060
|
-
if (res.status === 412) {
|
|
1061
|
-
// The signed conditional header fenced this write off: the remote
|
|
1062
|
-
// moved past our baseline (If-Match) or the key already exists
|
|
1063
|
-
// (If-None-Match). Same shape as the SDK's PreconditionFailed so the
|
|
1064
|
-
// push path routes both transports through one conflict handler.
|
|
1065
|
-
const detail = await safeText(res);
|
|
1066
|
-
throw preconditionFailedError(input.key, detail);
|
|
1067
|
-
}
|
|
1068
|
-
if (!res.ok) {
|
|
1069
|
-
const detail = await safeText(res);
|
|
1070
|
-
if (isObjectLockChecksumRequiredBody(res.status, detail)) {
|
|
1071
|
-
throw new ObjectLockChecksumRequiredError(input.key, detail);
|
|
1072
|
-
}
|
|
1073
|
-
throw new Error(`presigned PUT failed for ${input.key}: ${res.status} ${detail}`);
|
|
1074
|
-
}
|
|
1075
|
-
return { etag: stripQuotes(res.headers.get("etag") ?? undefined) };
|
|
1076
|
-
};
|
|
1077
|
-
return input.bypassBandwidthGovernor
|
|
1078
|
-
? send()
|
|
1079
|
-
: governor.measureRawTransfer(input.body.byteLength, send);
|
|
1080
|
-
};
|
|
1081
|
-
return input.bypassBandwidthGovernor
|
|
1082
|
-
? performPut()
|
|
1083
|
-
: getBandwidthGovernor().withChoreTransfer(performPut);
|
|
934
|
+
throw new Error(`presigned PUT failed for ${input.key}: ${res.status} ${detail}`);
|
|
935
|
+
}
|
|
936
|
+
return { etag: stripQuotes(res.headers.get("etag") ?? undefined) };
|
|
1084
937
|
}
|
|
1085
938
|
/**
|
|
1086
939
|
* True-streaming GET with bounded open-time outer retries.
|
|
@@ -1096,119 +949,81 @@ export class PresignObjectIO {
|
|
|
1096
949
|
* consumer that already received prefix bytes). That recovery lives at the
|
|
1097
950
|
* whole-download seam in s3.ts `downloadFile` (fresh stream → fresh temp).
|
|
1098
951
|
*/
|
|
1099
|
-
async getObjectStream(key
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
let
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
if (options.ifMatch) {
|
|
1134
|
-
requestHeaders["If-Match"] = quoteEtag(options.ifMatch);
|
|
1135
|
-
}
|
|
1136
|
-
res = await presignedGetWithRetry(row.url, Object.keys(requestHeaders).length > 0 ? requestHeaders : undefined, `presigned GET ${key}`);
|
|
1137
|
-
}
|
|
1138
|
-
catch (err) {
|
|
1139
|
-
// presignedGetWithRetry already burned same-URL connection retries.
|
|
1140
|
-
// One outer pass with a freshly minted URL recovers poisoned sockets
|
|
1141
|
-
// that keep failing on the same signed endpoint.
|
|
1142
|
-
if (isRetryablePresignedGetError(err) && attempt < FETCH_MAX_RETRIES) {
|
|
1143
|
-
lastError = err;
|
|
1144
|
-
forceFreshUrl = true;
|
|
1145
|
-
continue;
|
|
1146
|
-
}
|
|
1147
|
-
throw err;
|
|
1148
|
-
}
|
|
1149
|
-
if (res.status === 404) {
|
|
1150
|
-
res.destroy();
|
|
1151
|
-
throw notFoundError(key);
|
|
1152
|
-
}
|
|
1153
|
-
if (res.status === 403) {
|
|
1154
|
-
const detail = await safePresignedGetText(res);
|
|
1155
|
-
this.invalidateGetCache(key);
|
|
1156
|
-
if (isExpiredPresignDetail(detail) && attempt < FETCH_MAX_RETRIES) {
|
|
1157
|
-
lastError = new Error(`presigned GET expired for ${key}: 403 ${detail}`);
|
|
1158
|
-
forceFreshUrl = true;
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
// True ACL/KMS/bucket denial — never conflate with absence, and do
|
|
1162
|
-
// not burn re-presigns on a definitive Forbidden.
|
|
1163
|
-
throw accessDeniedError(key, detail || "presigned GET returned 403");
|
|
1164
|
-
}
|
|
1165
|
-
if (res.status === 412 || res.status === 416) {
|
|
1166
|
-
const detail = await safePresignedGetText(res);
|
|
1167
|
-
throw preconditionFailedError(key, detail);
|
|
952
|
+
async getObjectStream(key) {
|
|
953
|
+
let lastError;
|
|
954
|
+
// After a proven-expired URL or exhausted same-URL transport failure, the
|
|
955
|
+
// next attempt must mint a new presign rather than replaying a dead URL.
|
|
956
|
+
let forceFreshUrl = false;
|
|
957
|
+
for (let attempt = 0; attempt <= FETCH_MAX_RETRIES; attempt++) {
|
|
958
|
+
if (attempt > 0) {
|
|
959
|
+
const backoff = FETCH_BASE_DELAY_MS * 2 ** (attempt - 1);
|
|
960
|
+
const jitter = Math.floor(Math.random() * FETCH_BASE_DELAY_MS);
|
|
961
|
+
await sleep(backoff + jitter);
|
|
962
|
+
}
|
|
963
|
+
// RateLimited / per-key Forbidden from the mint path are definitive and
|
|
964
|
+
// propagate to the caller without outer transport retry.
|
|
965
|
+
let row;
|
|
966
|
+
if (forceFreshUrl) {
|
|
967
|
+
this.invalidateGetCache(key);
|
|
968
|
+
row = await this.presignSingle("get", key);
|
|
969
|
+
}
|
|
970
|
+
else {
|
|
971
|
+
row = await this.resolveGetUrlForBody(key);
|
|
972
|
+
}
|
|
973
|
+
forceFreshUrl = false;
|
|
974
|
+
let res;
|
|
975
|
+
try {
|
|
976
|
+
res = await presignedGetWithRetry(row.url, row.headers, `presigned GET ${key}`);
|
|
977
|
+
}
|
|
978
|
+
catch (err) {
|
|
979
|
+
// presignedGetWithRetry already burned same-URL connection retries.
|
|
980
|
+
// One outer pass with a freshly minted URL recovers poisoned sockets
|
|
981
|
+
// that keep failing on the same signed endpoint.
|
|
982
|
+
if (isRetryablePresignedGetError(err) && attempt < FETCH_MAX_RETRIES) {
|
|
983
|
+
lastError = err;
|
|
984
|
+
forceFreshUrl = true;
|
|
985
|
+
continue;
|
|
1168
986
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
987
|
+
throw err;
|
|
988
|
+
}
|
|
989
|
+
if (res.status === 404) {
|
|
990
|
+
res.destroy();
|
|
991
|
+
throw notFoundError(key);
|
|
992
|
+
}
|
|
993
|
+
if (res.status === 403) {
|
|
994
|
+
const detail = await safePresignedGetText(res);
|
|
995
|
+
this.invalidateGetCache(key);
|
|
996
|
+
if (isExpiredPresignDetail(detail) && attempt < FETCH_MAX_RETRIES) {
|
|
997
|
+
lastError = new Error(`presigned GET expired for ${key}: 403 ${detail}`);
|
|
998
|
+
forceFreshUrl = true;
|
|
999
|
+
continue;
|
|
1174
1000
|
}
|
|
1175
|
-
//
|
|
1176
|
-
//
|
|
1177
|
-
|
|
1178
|
-
const rawBody = res.body ?? (async function* () { })();
|
|
1179
|
-
const observedBody = options.bypassBandwidthGovernor
|
|
1180
|
-
? rawBody
|
|
1181
|
-
: governor.observeRawBody(rawBody);
|
|
1182
|
-
const idleBoundBody = withObjectBodyIdleTimeout(observedBody, key, objectIOBodyIdleTimeoutMs(), (error) => res.destroy(error));
|
|
1183
|
-
const result = {
|
|
1184
|
-
body: options.bypassBandwidthGovernor
|
|
1185
|
-
? idleBoundBody
|
|
1186
|
-
: governor.governBody(idleBoundBody, release),
|
|
1187
|
-
metadata: metaFromHeaders(res.headers),
|
|
1188
|
-
etag: res.headers.get("etag") ?? undefined,
|
|
1189
|
-
versionId: res.headers.get("x-amz-version-id") ?? undefined,
|
|
1190
|
-
contentLength: expectedContentLength(res.headers),
|
|
1191
|
-
contentRange: res.headers.get("content-range") ?? undefined,
|
|
1192
|
-
statusCode: res.status,
|
|
1193
|
-
destroy: (error) => {
|
|
1194
|
-
res.destroy(error);
|
|
1195
|
-
release?.();
|
|
1196
|
-
},
|
|
1197
|
-
};
|
|
1198
|
-
leaseHandedOff = true;
|
|
1199
|
-
return result;
|
|
1001
|
+
// True ACL/KMS/bucket denial — never conflate with absence, and do
|
|
1002
|
+
// not burn re-presigns on a definitive Forbidden.
|
|
1003
|
+
throw accessDeniedError(key, detail || "presigned GET returned 403");
|
|
1200
1004
|
}
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1005
|
+
if (res.status < 200 || res.status >= 300) {
|
|
1006
|
+
// Transient 5xx already retried inside presignedGetWithRetry; a final
|
|
1007
|
+
// non-ok status is reported to the caller without outer re-presign.
|
|
1008
|
+
const detail = await safePresignedGetText(res);
|
|
1009
|
+
throw new Error(`presigned GET failed for ${key}: ${res.status} ${detail}`);
|
|
1010
|
+
}
|
|
1011
|
+
// Live body stream — do not drain. Callers that need a Buffer use
|
|
1012
|
+
// getObject; downloadFile streams to a temp path and retries mid-stream
|
|
1013
|
+
// transport cuts around the whole attempt.
|
|
1014
|
+
return {
|
|
1015
|
+
// Data-plane pacing: chunks acquire governor tokens before yielding
|
|
1016
|
+
// (backpressure — the socket pauses while we wait).
|
|
1017
|
+
body: getBandwidthGovernor().throttleBody(res.body ?? (async function* () { })()),
|
|
1018
|
+
metadata: metaFromHeaders(res.headers),
|
|
1019
|
+
};
|
|
1208
1020
|
}
|
|
1021
|
+
throw lastError instanceof Error
|
|
1022
|
+
? lastError
|
|
1023
|
+
: new Error(`presigned GET ${key}: failed after ${FETCH_MAX_RETRIES} retries`);
|
|
1209
1024
|
}
|
|
1210
|
-
async getObject(key
|
|
1211
|
-
const res = await this.getObjectStream(key
|
|
1025
|
+
async getObject(key) {
|
|
1026
|
+
const res = await this.getObjectStream(key);
|
|
1212
1027
|
const body = await drainToBuffer(res.body);
|
|
1213
1028
|
return { body, metadata: res.metadata };
|
|
1214
1029
|
}
|
|
@@ -1318,7 +1133,6 @@ export class PresignObjectIO {
|
|
|
1318
1133
|
lastModified: parseLastModified(res.headers.get("last-modified")),
|
|
1319
1134
|
etag: stripQuotes(res.headers.get("etag") ?? undefined),
|
|
1320
1135
|
size: Number(res.headers.get("content-length") ?? "0"),
|
|
1321
|
-
versionId: res.headers.get("x-amz-version-id") ?? undefined,
|
|
1322
1136
|
storageClass: res.headers.get("x-amz-storage-class") ?? "STANDARD",
|
|
1323
1137
|
metadata: metaFromHeaders(res.headers),
|
|
1324
1138
|
};
|