@uru-intelligence/app 2.2.4 → 2.2.5
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/README.md +24 -11
- package/dist/files.js +10 -4
- package/dist/jobs.js +5 -2
- package/dist/transport-invocation.js +13 -2
- package/dist/transport-retry.d.ts +30 -14
- package/dist/transport-retry.js +73 -20
- package/dist/transport.js +2 -1
- package/dist/uploads.js +9 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -433,10 +433,11 @@ attempt can run safely.
|
|
|
433
433
|
|
|
434
434
|
Uru also runs the job again when the handler throws a temporary answer from
|
|
435
435
|
Uru after the SDK's own resends ran out: a 408, 429 or 503 that does not say
|
|
436
|
-
`retryable: false`,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
`retryable: false`, a 502 or 504 that no server answered, Cloudflare's own 520
|
|
437
|
+
to 527 or 530, or a 500 with no Uru error code, which a proxy in front of Uru
|
|
438
|
+
gave. This needs a job that is still retryable (see below), an attempt left
|
|
439
|
+
(three in all), and no cancel. Any other answer ends the job: a 500 with Uru's
|
|
440
|
+
error code, a 403, 404, 409 or 422, or an error from your own code.
|
|
440
441
|
|
|
441
442
|
On the next attempt:
|
|
442
443
|
|
|
@@ -545,8 +546,8 @@ const response = await app.query('summary', {}, { onStatus: event => render(even
|
|
|
545
546
|
A custom retry wait can accept the optional `AbortSignal` to stop its own
|
|
546
547
|
work. The SDK still bounds the call when that wait ignores the signal.
|
|
547
548
|
- **Calls ride out a restarting server.** When Uru gives no answer (a failed
|
|
548
|
-
or reset connection, a reply cut off after its headers, HTTP 502 or 504,
|
|
549
|
-
|
|
549
|
+
or reset connection, a reply cut off after its headers, HTTP 502 or 504, a
|
|
550
|
+
503 without an Uru error code, or Cloudflare's own 520 to 527 or 530),
|
|
550
551
|
the client sends the call again after about 0.5, 1, 2, 4, 8, 8 and 8
|
|
551
552
|
seconds, each stretched by up to twice for jitter: about a minute in all.
|
|
552
553
|
Each wait reports a `reconnecting` status event. An action or a job start
|
|
@@ -565,7 +566,10 @@ const response = await app.query('summary', {}, { onStatus: event => render(even
|
|
|
565
566
|
some Datasets and not others: do not send it again with a new key, which
|
|
566
567
|
writes the saved Datasets again. The caller's
|
|
567
568
|
`signal` and `timeoutMs` end the waits. Set `dampers.maxTransportRetries` to
|
|
568
|
-
`0` to turn resends off.
|
|
569
|
+
`0` to turn resends off. The SDK then does not tell the Uru gateway of a
|
|
570
|
+
hosted job that it resends, so the gateway may still send a call that is safe
|
|
571
|
+
to repeat again after a lost answer, a temporary answer or a 500 with no Uru
|
|
572
|
+
error code.
|
|
569
573
|
- **Job writes ride out a short database stall.** A Dataset row write with a
|
|
570
574
|
key, `jobs.progress` and `jobs.checkpoint` are also sent again when Uru
|
|
571
575
|
answers that it cannot serve the call now: HTTP 408, 429 or 503. They use
|
|
@@ -573,10 +577,19 @@ const response = await app.query('summary', {}, { onStatus: event => render(even
|
|
|
573
577
|
`Retry-After` is longer than the wait time that is left, the call throws
|
|
574
578
|
that answer at once and never sends before the server allows. A row
|
|
575
579
|
write sends the same key each time, so the server joins the first command
|
|
576
|
-
and never writes twice.
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
+
and never writes twice. They are also sent again, at most twice, after a
|
|
581
|
+
500 with no Uru error code: Uru answers its own 500 with an error code, so
|
|
582
|
+
a 500 without one came from a proxy in front of Uru. Every other answer is
|
|
583
|
+
final and is never sent again: a 500 with Uru's error code, a 403, 404,
|
|
584
|
+
409, 422 or any other status, an error body with `retryable: false`, or a
|
|
585
|
+
setup failure that a resend cannot fix. When the resends run out, the call
|
|
586
|
+
throws `UruAppRuntimeError` with the last status and the answer's parsed
|
|
587
|
+
body. A file call and an upload that are not accepted keep that body too.
|
|
588
|
+
- **A query rides out a short stall too.** A query only reads, so it is also
|
|
589
|
+
sent again, with a new key, after HTTP 408 or a 503 that is not final, such
|
|
590
|
+
as Uru's 503 when its database pool is full for a moment. It uses the
|
|
591
|
+
lost-answer waits above. A 429 keeps its rate-limit waits, and an action or
|
|
592
|
+
a job start keeps a temporary answer as its result.
|
|
580
593
|
- **How long a call can take.** All the waits of one call add up to at most
|
|
581
594
|
63 seconds. A send that gets no answer counts as lost after 30 seconds, so
|
|
582
595
|
in the worst case (8 sends that each run 30 seconds) a Dataset row write,
|
package/dist/files.js
CHANGED
|
@@ -4,6 +4,8 @@ import { isRuntimeJsonObject } from './transport-json.js';
|
|
|
4
4
|
const LIBRARY_READ_BYTES = 5 * 1024 * 1024;
|
|
5
5
|
const OUTPUT_BYTES = 10 * 1024 * 1024;
|
|
6
6
|
const RESPONSE_BYTES = Math.ceil(OUTPUT_BYTES / 3) * 4 + 8192;
|
|
7
|
+
// Uru's error envelope and an edge's error page are far smaller than this.
|
|
8
|
+
const ERROR_BODY_BYTES = 64 * 1024;
|
|
7
9
|
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
10
|
const HASH = /^[0-9a-f]{64}$/;
|
|
9
11
|
function invalid() {
|
|
@@ -57,7 +59,7 @@ function base64(bytes) {
|
|
|
57
59
|
}
|
|
58
60
|
return btoa(binary);
|
|
59
61
|
}
|
|
60
|
-
async function readJson(response) {
|
|
62
|
+
async function readJson(response, maxBytes = RESPONSE_BYTES) {
|
|
61
63
|
const reader = response.body?.getReader();
|
|
62
64
|
if (reader === undefined)
|
|
63
65
|
invalid();
|
|
@@ -70,7 +72,7 @@ async function readJson(response) {
|
|
|
70
72
|
if (chunk.done)
|
|
71
73
|
break;
|
|
72
74
|
size += chunk.value.byteLength;
|
|
73
|
-
if (size >
|
|
75
|
+
if (size > maxBytes) {
|
|
74
76
|
await reader.cancel();
|
|
75
77
|
invalid();
|
|
76
78
|
}
|
|
@@ -100,8 +102,12 @@ export function createFilesContext(options) {
|
|
|
100
102
|
signal: signal === undefined ? AbortSignal.timeout(30_000) : AbortSignal.any([signal, AbortSignal.timeout(30_000)]),
|
|
101
103
|
});
|
|
102
104
|
if (!response.ok) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
+
// The answer's body goes with the error, null when it is not JSON. The
|
|
106
|
+
// job runner reads its error code: a 500 with Uru's code ends the job,
|
|
107
|
+
// and a 500 with none came from an edge, so a retry-safe job gets its
|
|
108
|
+
// next attempt.
|
|
109
|
+
const body = await readJson(response, ERROR_BODY_BYTES).catch(() => null);
|
|
110
|
+
throw new UruAppRuntimeError('File access was not accepted.', { status: response.status, body });
|
|
105
111
|
}
|
|
106
112
|
return readJson(response);
|
|
107
113
|
};
|
package/dist/jobs.js
CHANGED
|
@@ -18,7 +18,7 @@ const postJobUpdate = async (options, env, operation, body) => {
|
|
|
18
18
|
// temporary answer such as the job token's 503 during a short database
|
|
19
19
|
// stall. A temporary answer comes before the route saves anything. Each one
|
|
20
20
|
// also keeps the attempt's lease: it proves the job is alive.
|
|
21
|
-
const { response } = await postWithResends({
|
|
21
|
+
const { body: answer, response } = await postWithResends({
|
|
22
22
|
body,
|
|
23
23
|
config: resolveDamperConfig(options.dampers),
|
|
24
24
|
headers,
|
|
@@ -27,8 +27,11 @@ const postJobUpdate = async (options, env, operation, body) => {
|
|
|
27
27
|
sendTimeoutMs: 30_000,
|
|
28
28
|
url,
|
|
29
29
|
});
|
|
30
|
+
// The answer's body goes with the error. The job runner reads its error
|
|
31
|
+
// code: a 500 with Uru's code ends the job, and a 500 with none came from
|
|
32
|
+
// an edge, so a retry-safe job gets its next attempt.
|
|
30
33
|
if (!response.ok) {
|
|
31
|
-
throw new UruAppRuntimeError('Job update was not accepted.', { status: response.status, body:
|
|
34
|
+
throw new UruAppRuntimeError('Job update was not accepted.', { status: response.status, body: answer });
|
|
32
35
|
}
|
|
33
36
|
};
|
|
34
37
|
const noJobAttempt = () => new UruAppRuntimeError('Job updates require an active job attempt.', { status: 0, body: null });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computeRateLimitRetryDelayMs, parseRetryable, parseRetryAfterSeconds, } from "./dampers.js";
|
|
2
2
|
import { awaitWithAbort } from "./transport-deadline.js";
|
|
3
|
-
import { canResend, isLostRequest, isLostResponse, readRuntimeResponseBody, resendDelayMs, waitBeforeResend, } from "./transport-retry.js";
|
|
3
|
+
import { canResend, isLostRequest, isLostResponse, isTemporaryAnswer, readRuntimeResponseBody, resendDelayMs, waitBeforeResend, } from "./transport-retry.js";
|
|
4
4
|
const FIRST_SEND = { rateLimited: 0, resent: 0 };
|
|
5
5
|
/** One send. A lost request comes back as an outcome so the caller can decide. */
|
|
6
6
|
const sendOnce = async (runtimeFetch, url, init, signal) => {
|
|
@@ -26,6 +26,17 @@ const sendOnce = async (runtimeFetch, url, init, signal) => {
|
|
|
26
26
|
/** Whether a send ended without an answer from the platform. */
|
|
27
27
|
const isLost = (outcome) => outcome.kind !== "response" ||
|
|
28
28
|
isLostResponse(outcome.result.response.status, outcome.result.body);
|
|
29
|
+
/**
|
|
30
|
+
* Whether a query got a temporary answer: a 408, or a 503 that is not final
|
|
31
|
+
* ({@link isTemporaryAnswer}), such as the API's 503 when its database pool
|
|
32
|
+
* is full for a moment. A query only reads, so it is sent again, as after a
|
|
33
|
+
* lost answer. A 429 keeps its own rate-limit waits. An action or a job keeps
|
|
34
|
+
* the answer: its key replays a stored run, which may hold that answer.
|
|
35
|
+
*/
|
|
36
|
+
const isTemporaryQueryAnswer = (capabilityType, outcome) => capabilityType === "query" &&
|
|
37
|
+
outcome.kind === "response" &&
|
|
38
|
+
outcome.result.response.status !== 429 &&
|
|
39
|
+
isTemporaryAnswer(outcome.result.response.status, outcome.result.body);
|
|
29
40
|
/** Report the coming resend, then wait for it. */
|
|
30
41
|
const reconnect = async (damper, resent, signal, report) => {
|
|
31
42
|
const delayMs = resendDelayMs(resent, damper.config.random);
|
|
@@ -42,7 +53,7 @@ export const fetchInvocation = async (args, counts = FIRST_SEND) => {
|
|
|
42
53
|
headers: args.headers,
|
|
43
54
|
method: "POST",
|
|
44
55
|
}, args.signal);
|
|
45
|
-
if (isLost(outcome) &&
|
|
56
|
+
if ((isLost(outcome) || isTemporaryQueryAnswer(args.capabilityType, outcome)) &&
|
|
46
57
|
args.resendLost &&
|
|
47
58
|
canResend(args.damper.config, counts.resent)) {
|
|
48
59
|
await reconnect(args.damper, counts.resent, args.signal, retryAfterSeconds => args.emit({
|
|
@@ -3,18 +3,31 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A deploy, a crash or a memory kill of one API replica shows up here as a
|
|
5
5
|
* failed or reset connection, a reply cut off after its headers, a 502 or 504
|
|
6
|
-
* from the edge,
|
|
6
|
+
* from the edge, a 503 from an edge with no healthy replica, or Cloudflare's
|
|
7
|
+
* own 520 to 527 or 530 when the origin gave it no valid answer. None of them
|
|
7
8
|
* is an answer from Uru: the call may not have arrived, or it arrived and its
|
|
8
9
|
* reply was lost. A short database stall shows up as a temporary answer from
|
|
9
|
-
* Uru: a 408, a 429 or a 503.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Uru: a 408, a 429 or a 503. An edge can also answer a plain 500 of its own
|
|
11
|
+
* ({@link isBareServerError}). Each caller decides whether its request is
|
|
12
|
+
* safe to send again (a keyed Dataset write is, a Dataset SQL statement is
|
|
13
|
+
* not); this module owns what counts as lost, what counts as temporary, and
|
|
14
|
+
* how long to wait.
|
|
13
15
|
*/
|
|
14
16
|
import type { ResolvedDamperConfig } from "./dampers.js";
|
|
15
17
|
import type { RuntimeFetch } from "./runtime.js";
|
|
16
18
|
/** A status the edge gives when no replica answered. */
|
|
17
19
|
export declare const isLostResponse: (status: number, body: unknown) => boolean;
|
|
20
|
+
/**
|
|
21
|
+
* An answer from Uru that it cannot serve the call now but can soon: a 408,
|
|
22
|
+
* a 429 or a 503 (HTTP defines 503 as temporary, RFC 9110 section 15.6.4).
|
|
23
|
+
* Every other status is final, whatever its body says: a 500 with Uru's error
|
|
24
|
+
* code means the call failed in a way that a resend repeats, and a 4xx such
|
|
25
|
+
* as 403, 404, 409 or 422 refuses this request. A body that says
|
|
26
|
+
* `retryable: false` (a Dataset job that ended) or names a missing setup is
|
|
27
|
+
* final too. A 500 with no Uru error code is not Uru's answer
|
|
28
|
+
* ({@link isBareServerError}).
|
|
29
|
+
*/
|
|
30
|
+
export declare const isTemporaryAnswer: (status: number, body: unknown) => boolean;
|
|
18
31
|
/** A fetch that failed before a response, and not because the caller stopped it. */
|
|
19
32
|
export declare const isLostRequest: (error: unknown, signal: AbortSignal | undefined) => boolean;
|
|
20
33
|
/** One response body, and whether the connection broke before all of it arrived. */
|
|
@@ -43,9 +56,11 @@ export interface PostWithResendsArguments {
|
|
|
43
56
|
/**
|
|
44
57
|
* Whether the same body is safe to send again: the server answers a keyed
|
|
45
58
|
* command from its first run, or the call replaces saved state. Such a call
|
|
46
|
-
* is sent again after a lost response
|
|
47
|
-
* ({@link isTemporaryAnswer})
|
|
48
|
-
*
|
|
59
|
+
* is sent again after a lost response, after a temporary answer
|
|
60
|
+
* ({@link isTemporaryAnswer}) and, a few times, after a bare 500
|
|
61
|
+
* ({@link isBareServerError}), and carries {@link SDK_RESENDS_HEADER} and
|
|
62
|
+
* {@link SDK_RESENDS_BARE_500_HEADER} (unless `maxTransportRetries` is 0).
|
|
63
|
+
* Any other call is sent once.
|
|
49
64
|
*/
|
|
50
65
|
readonly repeatable: boolean;
|
|
51
66
|
readonly runtimeFetch: RuntimeFetch;
|
|
@@ -59,10 +74,11 @@ export interface PostWithResendsResult {
|
|
|
59
74
|
readonly response: Response;
|
|
60
75
|
}
|
|
61
76
|
/**
|
|
62
|
-
* POST one prepared body. When the platform gave no answer
|
|
63
|
-
* answer, and the call is repeatable, send the same bytes again
|
|
64
|
-
* {@link resendWaitMs}. The resends stop at `maxTransportRetries
|
|
65
|
-
* wait budget is spent,
|
|
66
|
-
* answer
|
|
77
|
+
* POST one prepared body. When the platform gave no answer, a temporary
|
|
78
|
+
* answer or a bare 500, and the call is repeatable, send the same bytes again
|
|
79
|
+
* after {@link resendWaitMs}. The resends stop at `maxTransportRetries`, when
|
|
80
|
+
* the wait budget is spent, or after {@link BARE_SERVER_ERROR_RESENDS} bare
|
|
81
|
+
* 500s, and the last answer then goes to the caller. A final answer is never
|
|
82
|
+
* sent again. `bareServerErrors` counts the bare 500s before this send.
|
|
67
83
|
*/
|
|
68
|
-
export declare const postWithResends: (args: PostWithResendsArguments, resent?: number, waitedMs?: number) => Promise<PostWithResendsResult>;
|
|
84
|
+
export declare const postWithResends: (args: PostWithResendsArguments, resent?: number, waitedMs?: number, bareServerErrors?: number) => Promise<PostWithResendsResult>;
|
package/dist/transport-retry.js
CHANGED
|
@@ -3,13 +3,15 @@
|
|
|
3
3
|
*
|
|
4
4
|
* A deploy, a crash or a memory kill of one API replica shows up here as a
|
|
5
5
|
* failed or reset connection, a reply cut off after its headers, a 502 or 504
|
|
6
|
-
* from the edge,
|
|
6
|
+
* from the edge, a 503 from an edge with no healthy replica, or Cloudflare's
|
|
7
|
+
* own 520 to 527 or 530 when the origin gave it no valid answer. None of them
|
|
7
8
|
* is an answer from Uru: the call may not have arrived, or it arrived and its
|
|
8
9
|
* reply was lost. A short database stall shows up as a temporary answer from
|
|
9
|
-
* Uru: a 408, a 429 or a 503.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Uru: a 408, a 429 or a 503. An edge can also answer a plain 500 of its own
|
|
11
|
+
* ({@link isBareServerError}). Each caller decides whether its request is
|
|
12
|
+
* safe to send again (a keyed Dataset write is, a Dataset SQL statement is
|
|
13
|
+
* not); this module owns what counts as lost, what counts as temporary, and
|
|
14
|
+
* how long to wait.
|
|
13
15
|
*/
|
|
14
16
|
import { parseRetryable, parseRetryAfterSeconds } from "./dampers.js";
|
|
15
17
|
import { abortReason, awaitWithAbort } from "./transport-deadline.js";
|
|
@@ -55,9 +57,16 @@ const ownedErrorCode = (body) => {
|
|
|
55
57
|
codeOf(safeRecordValue(body, "code")) ??
|
|
56
58
|
(isRecord(error) ? codeOf(safeRecordValue(error, "code")) : null));
|
|
57
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Cloudflare's own statuses for an origin that gave no valid answer: it was
|
|
62
|
+
* down, refused or dropped the connection, or did not answer in time. Uru
|
|
63
|
+
* never sends them.
|
|
64
|
+
*/
|
|
65
|
+
const isEdgeOriginStatus = (status) => (status >= 520 && status <= 527) || status === 530;
|
|
58
66
|
/** A status the edge gives when no replica answered. */
|
|
59
67
|
export const isLostResponse = (status, body) => status === 502 ||
|
|
60
68
|
status === 504 ||
|
|
69
|
+
isEdgeOriginStatus(status) ||
|
|
61
70
|
(status === 503 && ownedErrorCode(body) === null);
|
|
62
71
|
/** The statuses Uru gives when it cannot serve a call now but can soon. */
|
|
63
72
|
const TEMPORARY_STATUSES = new Set([408, 429, 503]);
|
|
@@ -71,12 +80,14 @@ const SETUP_FAILURE_CODES = new Set([
|
|
|
71
80
|
/**
|
|
72
81
|
* An answer from Uru that it cannot serve the call now but can soon: a 408,
|
|
73
82
|
* a 429 or a 503 (HTTP defines 503 as temporary, RFC 9110 section 15.6.4).
|
|
74
|
-
* Every other status is final, whatever its body says: a 500
|
|
75
|
-
* failed in a way that a resend repeats, and a 4xx such
|
|
76
|
-
* 422 refuses this request. A body that says
|
|
77
|
-
* job that ended) or names a missing setup is
|
|
83
|
+
* Every other status is final, whatever its body says: a 500 with Uru's error
|
|
84
|
+
* code means the call failed in a way that a resend repeats, and a 4xx such
|
|
85
|
+
* as 403, 404, 409 or 422 refuses this request. A body that says
|
|
86
|
+
* `retryable: false` (a Dataset job that ended) or names a missing setup is
|
|
87
|
+
* final too. A 500 with no Uru error code is not Uru's answer
|
|
88
|
+
* ({@link isBareServerError}).
|
|
78
89
|
*/
|
|
79
|
-
const isTemporaryAnswer = (status, body) => {
|
|
90
|
+
export const isTemporaryAnswer = (status, body) => {
|
|
80
91
|
if (!TEMPORARY_STATUSES.has(status))
|
|
81
92
|
return false;
|
|
82
93
|
if (parseRetryable(body) === false)
|
|
@@ -84,6 +95,25 @@ const isTemporaryAnswer = (status, body) => {
|
|
|
84
95
|
const code = ownedErrorCode(body);
|
|
85
96
|
return code === null || !SETUP_FAILURE_CODES.has(code);
|
|
86
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* A 500 with no Uru error code. The API answers every failure of its
|
|
100
|
+
* handlers, an unexpected throw too, in its error envelope with a code. So no
|
|
101
|
+
* API handler wrote this 500: an edge did (Traefik's own 500 for a proxy
|
|
102
|
+
* failure it has no other status for, as while an API replica starts;
|
|
103
|
+
* Cloudflare's own 500; a Worker that threw), or the API process failed
|
|
104
|
+
* outside its handlers. A call that may be sent again is sent again after
|
|
105
|
+
* it, but only a few times ({@link BARE_SERVER_ERROR_RESENDS}), because that
|
|
106
|
+
* last case can repeat.
|
|
107
|
+
*/
|
|
108
|
+
const isBareServerError = (status, body) => status === 500 && ownedErrorCode(body) === null;
|
|
109
|
+
/**
|
|
110
|
+
* The most resends that the bare 500s of one call get. They use the
|
|
111
|
+
* lost-answer waits, so a call whose first answer is a bare 500 that repeats
|
|
112
|
+
* ends about 1.5 to 3 seconds later. That covers the 2 seconds or so that
|
|
113
|
+
* Traefik answered 500 while an API replica started (PR #8488), and a 500
|
|
114
|
+
* that repeats costs at most 2 more sends.
|
|
115
|
+
*/
|
|
116
|
+
const BARE_SERVER_ERROR_RESENDS = 2;
|
|
87
117
|
/**
|
|
88
118
|
* The request header that tells the provider gateway this client sends a
|
|
89
119
|
* temporary answer again itself, so the gateway passes it straight back
|
|
@@ -91,6 +121,14 @@ const isTemporaryAnswer = (status, body) => {
|
|
|
91
121
|
* the API once for each SDK send times each gateway send.
|
|
92
122
|
*/
|
|
93
123
|
const SDK_RESENDS_HEADER = "x-uru-sdk-resends";
|
|
124
|
+
/**
|
|
125
|
+
* The same for a bare 500 ({@link isBareServerError}). It is a second header
|
|
126
|
+
* and not a second value of {@link SDK_RESENDS_HEADER}, because SDK 2.2.4
|
|
127
|
+
* sends that one too and gives a bare 500 to the caller, so the gateway has
|
|
128
|
+
* to send a bare 500 again for it. A gateway that does not know this header
|
|
129
|
+
* ignores it.
|
|
130
|
+
*/
|
|
131
|
+
const SDK_RESENDS_BARE_500_HEADER = "x-uru-sdk-resends-bare-500";
|
|
94
132
|
/** A fetch that failed before a response, and not because the caller stopped it. */
|
|
95
133
|
export const isLostRequest = (error, signal) => {
|
|
96
134
|
if (signal?.aborted === true)
|
|
@@ -192,19 +230,24 @@ const resendWaitMs = (args, resent, waitedMs, temporary) => {
|
|
|
192
230
|
return Math.min(Math.max(resendDelayMs(resent, args.config.random), retryAfter), left);
|
|
193
231
|
};
|
|
194
232
|
/**
|
|
195
|
-
* POST one prepared body. When the platform gave no answer
|
|
196
|
-
* answer, and the call is repeatable, send the same bytes again
|
|
197
|
-
* {@link resendWaitMs}. The resends stop at `maxTransportRetries
|
|
198
|
-
* wait budget is spent,
|
|
199
|
-
* answer
|
|
233
|
+
* POST one prepared body. When the platform gave no answer, a temporary
|
|
234
|
+
* answer or a bare 500, and the call is repeatable, send the same bytes again
|
|
235
|
+
* after {@link resendWaitMs}. The resends stop at `maxTransportRetries`, when
|
|
236
|
+
* the wait budget is spent, or after {@link BARE_SERVER_ERROR_RESENDS} bare
|
|
237
|
+
* 500s, and the last answer then goes to the caller. A final answer is never
|
|
238
|
+
* sent again. `bareServerErrors` counts the bare 500s before this send.
|
|
200
239
|
*/
|
|
201
|
-
export const postWithResends = async (args, resent = 0, waitedMs = 0) => {
|
|
240
|
+
export const postWithResends = async (args, resent = 0, waitedMs = 0, bareServerErrors = 0) => {
|
|
202
241
|
// Read the fetch out of `args` so it is not called with `args` as `this`.
|
|
203
242
|
const { runtimeFetch } = args;
|
|
204
243
|
const sendSignal = AbortSignal.timeout(args.sendTimeoutMs);
|
|
205
244
|
const headers = new Headers(args.headers);
|
|
206
|
-
|
|
245
|
+
// The headers say "I send this again myself". With `maxTransportRetries` at
|
|
246
|
+
// 0 that is false, so the gateway keeps its own resends.
|
|
247
|
+
if (args.repeatable && canResend(args.config, 0)) {
|
|
207
248
|
headers.set(SDK_RESENDS_HEADER, "temporary");
|
|
249
|
+
headers.set(SDK_RESENDS_BARE_500_HEADER, "1");
|
|
250
|
+
}
|
|
208
251
|
let outcome = null;
|
|
209
252
|
let cut = false;
|
|
210
253
|
let lostError = null;
|
|
@@ -226,13 +269,23 @@ export const postWithResends = async (args, resent = 0, waitedMs = 0) => {
|
|
|
226
269
|
lostError = error;
|
|
227
270
|
}
|
|
228
271
|
let temporary = null;
|
|
272
|
+
let bare = false;
|
|
229
273
|
if (outcome !== null &&
|
|
230
274
|
!cut &&
|
|
231
275
|
!isLostResponse(outcome.response.status, outcome.body)) {
|
|
232
|
-
|
|
276
|
+
bare = isBareServerError(outcome.response.status, outcome.body);
|
|
277
|
+
if (bare) {
|
|
278
|
+
// An edge's 500 says nothing about when to send again, so it keeps
|
|
279
|
+
// the lost-answer waits, as a 502 does.
|
|
280
|
+
if (bareServerErrors >= BARE_SERVER_ERROR_RESENDS)
|
|
281
|
+
return outcome;
|
|
282
|
+
}
|
|
283
|
+
else if (isTemporaryAnswer(outcome.response.status, outcome.body)) {
|
|
284
|
+
temporary = outcome;
|
|
285
|
+
}
|
|
286
|
+
else {
|
|
233
287
|
return outcome;
|
|
234
288
|
}
|
|
235
|
-
temporary = outcome;
|
|
236
289
|
}
|
|
237
290
|
const delayMs = resendWaitMs(args, resent, waitedMs, temporary);
|
|
238
291
|
if (delayMs === null) {
|
|
@@ -241,5 +294,5 @@ export const postWithResends = async (args, resent = 0, waitedMs = 0) => {
|
|
|
241
294
|
return outcome;
|
|
242
295
|
}
|
|
243
296
|
await waitBeforeResend(args.config, delayMs, undefined);
|
|
244
|
-
return await postWithResends(args, resent + 1, waitedMs + delayMs);
|
|
297
|
+
return await postWithResends(args, resent + 1, waitedMs + delayMs, bareServerErrors + (bare ? 1 : 0));
|
|
245
298
|
};
|
package/dist/transport.js
CHANGED
|
@@ -494,7 +494,8 @@ export const invokeAppRuntime = async (options, damper, capabilityType, name, in
|
|
|
494
494
|
// `maxRateLimitRetries` extra sends, honoring Retry-After / retry_after_seconds
|
|
495
495
|
// (capped) before falling through to the normal failure path. A response the
|
|
496
496
|
// platform never gave (a restarting replica) is sent again separately, at
|
|
497
|
-
// most `maxTransportRetries` times, when the call is safe to send again.
|
|
497
|
+
// most `maxTransportRetries` times, when the call is safe to send again. So
|
|
498
|
+
// is a query's temporary answer: a query only reads.
|
|
498
499
|
const { body, response } = await withRuntimeRequestSignal(invocationOptions, async (requestSignal) => await fetchInvocation({
|
|
499
500
|
capabilityName,
|
|
500
501
|
capabilityType,
|
package/dist/uploads.js
CHANGED
|
@@ -277,10 +277,14 @@ export function createUploadsContext(options) {
|
|
|
277
277
|
: AbortSignal.any([signal, AbortSignal.timeout(30_000)]),
|
|
278
278
|
});
|
|
279
279
|
if (!response.ok) {
|
|
280
|
-
|
|
280
|
+
// The answer's body goes with the error, null when it is not JSON. The
|
|
281
|
+
// job runner reads its error code: a 500 with Uru's code ends the job,
|
|
282
|
+
// and a 500 with none came from an edge, so a retry-safe job gets its
|
|
283
|
+
// next attempt.
|
|
284
|
+
const body = await readJson(response).catch(() => null);
|
|
281
285
|
throw new UruAppRuntimeError('Upload request was not accepted.', {
|
|
282
286
|
status: response.status,
|
|
283
|
-
body
|
|
287
|
+
body,
|
|
284
288
|
});
|
|
285
289
|
}
|
|
286
290
|
return readJson(response);
|
|
@@ -343,10 +347,11 @@ export function createUploadsContext(options) {
|
|
|
343
347
|
: AbortSignal.any([settings.signal, AbortSignal.timeout(300_000)]),
|
|
344
348
|
});
|
|
345
349
|
if (!response.ok) {
|
|
346
|
-
|
|
350
|
+
// Uru's answer, not the file: its body goes with the error, as above.
|
|
351
|
+
const body = await readJson(response).catch(() => null);
|
|
347
352
|
throw new UruAppRuntimeError('Upload could not be read.', {
|
|
348
353
|
status: response.status,
|
|
349
|
-
body
|
|
354
|
+
body,
|
|
350
355
|
});
|
|
351
356
|
}
|
|
352
357
|
return readBlob(response);
|