arcadible 1.0.48 → 1.0.49

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.
@@ -12,6 +12,7 @@ import { HttpError } from "../../util/http.js";
12
12
  import { isRetry } from "../../config/retry.js";
13
13
  import { sleep } from "../../util/delay.js";
14
14
  import { isTable } from "../../util/objs.js";
15
+ import { TIMEOUT } from "../../util/request.js";
15
16
  import { channelOf, gameOf, headersOf, isRefused, REFUSED } from "../game.js";
16
17
  import { answerUnread, functionLogsFull, functionLogsRefused, functionLogsSinceInvalid, functionLogsVersionInvalid, gameNotOwned, unableToReach, } from "../../phrase/index.js";
17
18
  // [declare]
@@ -151,6 +152,7 @@ async function pageOf(token, query, last) {
151
152
  try {
152
153
  res = await fetch(query.size ? `${token.url}?${query.toString()}` : token.url, {
153
154
  headers: { authorization: `Bearer ${token.token}` },
155
+ signal: AbortSignal.timeout(TIMEOUT),
154
156
  });
155
157
  }
156
158
  catch (ex) {
@@ -10,6 +10,12 @@ import { client, id } from "../config/product.js";
10
10
  const CLIENT = client;
11
11
  const ID = id;
12
12
  const VERSION = version;
13
+ // how long a request waits on the API, its answer's body included, before
14
+ // it's api_unreachable: the API gives up on the database at 10 seconds, so
15
+ // one that hasn't answered in 30 isn't going to (LIMITS.md, How long things
16
+ // last), and a connection that hangs would otherwise hold the command for
17
+ // minutes.
18
+ export const TIMEOUT = 30_000;
13
19
  // [function]
14
20
  // the body as JSON, or null when it isn't JSON, such as a proxy's error page.
15
21
  function json(resp) {
@@ -59,8 +65,8 @@ function parse(resp) {
59
65
  // [function]
60
66
  // sends a request to a full URL. `headers` are added to the client's own, and
61
67
  // a form is sent as JSON, its fields as text; `{ json }` is sent as the JSON
62
- // it is. A request that gets no response, such as when offline, rejects as
63
- // api_unreachable.
68
+ // it is. A request that gets no response, such as when offline, or none in
69
+ // TIMEOUT, rejects as api_unreachable.
64
70
  function send(method, url, form, headers = {}) {
65
71
  const all = {
66
72
  [`X-${CLIENT}-Client-Id`]: ID,
@@ -73,15 +79,19 @@ function send(method, url, form, headers = {}) {
73
79
  : form instanceof FormData
74
80
  ? JSON.stringify(Object.fromEntries(form))
75
81
  : JSON.stringify(form.json);
82
+ const unreachable = (ex) => {
83
+ throw new ArcError(API_UNREACHABLE, unableToReach(), {
84
+ cause: ex,
85
+ });
86
+ };
76
87
  return fetch(url, {
77
88
  body,
78
89
  headers: all,
79
90
  method,
80
- }).then(parse, (ex) => {
81
- throw new ArcError(API_UNREACHABLE, unableToReach(), {
82
- cause: ex,
83
- });
84
- });
91
+ signal: AbortSignal.timeout(TIMEOUT),
92
+ }).then(
93
+ // a body cut off by the clock is unreachable too; a refusal is the API's
94
+ (resp) => parse(resp).catch((ex) => ex instanceof HttpError ? Promise.reject(ex) : unreachable(ex)), unreachable);
85
95
  }
86
96
  // [function]
87
97
  export function get(url, headers) {
package/dist/util/s3.js CHANGED
@@ -7,6 +7,11 @@ import { ArcError } from "./error.js";
7
7
  import { unableToReach, uploadFailed } from "../phrase/index.js";
8
8
  // [declare]
9
9
  const CHECKSUM = "x-amz-checksum-sha256";
10
+ // how long the upload's connection may sit with nothing sent or answered
11
+ // before it's api_unreachable: idle, not the whole upload, which takes as
12
+ // long as the zip's size and the connection make it (LIMITS.md, How long
13
+ // things last).
14
+ export const IDLE = 60_000;
10
15
  // [function]
11
16
  // whether the upload link signs `header`, which must then be sent.
12
17
  function signs(url, header) {
@@ -30,8 +35,8 @@ function requestOpts(url, { sha256, size }) {
30
35
  }
31
36
  // [function]
32
37
  // puts the file to the upload link, and resolves once S3 accepts it. A
33
- // request that gets no response rejects as api_unreachable; a file that can't
34
- // be read rejects with its own error.
38
+ // request that gets no response, or sits idle for IDLE, rejects as
39
+ // api_unreachable; a file that can't be read rejects with its own error.
35
40
  // `https.request` is called through the module, as it is when the request is
36
41
  // made, so the tests' sandbox can replace it (test/support/preload.js).
37
42
  export function upload(url, { path, sha256, size }, onProgress) {
@@ -46,6 +51,9 @@ export function upload(url, { path, sha256, size }, onProgress) {
46
51
  reject(new ArcError(UPLOAD_FAILED, uploadFailed(status), { status }));
47
52
  });
48
53
  let readError = null;
54
+ req.setTimeout(IDLE, () => {
55
+ req.destroy(new DOMException(`No progress in ${IDLE / 1000} seconds.`, "TimeoutError"));
56
+ });
49
57
  req.on("error", (ex) => {
50
58
  reject(readError ??
51
59
  new ArcError(API_UNREACHABLE, unableToReach(), {
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "license": "Apache-2.0",
44
44
  "name": "arcadible",
45
- "version": "1.0.48"
45
+ "version": "1.0.49"
46
46
  },
47
47
  "node_modules/@cacheable/memory": {
48
48
  "dependencies": {
@@ -2433,5 +2433,5 @@
2433
2433
  }
2434
2434
  },
2435
2435
  "requires": true,
2436
- "version": "1.0.48"
2436
+ "version": "1.0.49"
2437
2437
  }
package/package.json CHANGED
@@ -67,5 +67,5 @@
67
67
  "test": "tsc && npm run lint && node --test \"test/**/*.test.js\" \"test/**/*.test.mjs\""
68
68
  },
69
69
  "type": "module",
70
- "version": "1.0.48"
70
+ "version": "1.0.49"
71
71
  }