@molecule/api-code-sandbox-flyio 1.3.2 → 1.3.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,KAAK,EAYV,eAAe,EAGhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAA;AAwBrE,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAIV,WAAW,EAUZ,MAAM,YAAY,CAAA;AAkBnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E;AAkyFD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,CAEjB"}
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAYV,eAAe,EAGhB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,EAAE,YAAY,EAAgC,MAAM,UAAU,CAAA;AAwBrE,OAAO,EAAmD,KAAK,WAAW,EAAE,MAAM,cAAc,CAAA;AAEhG,OAAO,KAAK,EAIV,WAAW,EAUZ,MAAM,YAAY,CAAA;AAkBnB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAIjG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE5E;AA8yFD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAC5B,MAAM,CAAC,EAAE,WAAW,EACpB,MAAM,CAAC,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,WAAW,GAAG,IAAI,GACzB,eAAe,CAEjB"}
package/dist/provider.js CHANGED
@@ -7,7 +7,8 @@
7
7
  * @module
8
8
  */
9
9
  import { createHash } from 'node:crypto';
10
- import { gzipSync } from 'node:zlib';
10
+ import { promisify } from 'node:util';
11
+ import { gzip } from 'node:zlib';
11
12
  import { getLogger } from '@molecule/api-bond';
12
13
  import { t } from '@molecule/api-i18n';
13
14
  import { FlyApiClient, FlyApiError, normalizeApiUrl } from './api.js';
@@ -272,6 +273,13 @@ const IMPORT_WRITE_CHUNK_BASE64 = 12_000;
272
273
  * the single download happen back-to-back.
273
274
  */
274
275
  const IMPORT_PRESIGN_EXPIRY_SECONDS = 3600;
276
+ /**
277
+ * zlib's gzip on the libuv thread pool. {@link Sandbox.importFiles} compresses
278
+ * a whole deploy archive (hundreds of MB), and the synchronous form ran on the
279
+ * caller's event loop for its full duration — seconds in which a server process
280
+ * hosting this provider answered no request at all.
281
+ */
282
+ const gzipAsync = promisify(gzip);
275
283
  /** Extra seconds allowed for the probe exec beyond its connection budget. */
276
284
  const PROBE_EXEC_HEADROOM_SECONDS = 10;
277
285
  /**
@@ -2336,7 +2344,8 @@ class FlyioSandboxProvider {
2336
2344
  *
2337
2345
  * The Fly Machines exec endpoint is a single request/response with no
2338
2346
  * stdin, so the archive cannot be piped to `tar` directly. It is buffered,
2339
- * gzipped (fewer bytes = fewer exec round trips over the base64 channel),
2347
+ * gzipped on the thread pool, never on the caller's event loop (fewer
2348
+ * bytes = fewer exec round trips over the base64 channel),
2340
2349
  * written to a temp file in `WRITE_CHUNK_BASE64`-sized pieces the same way
2341
2350
  * `writeFile` does, then extracted.
2342
2351
  *
@@ -2351,7 +2360,10 @@ class FlyioSandboxProvider {
2351
2360
  const parts = [];
2352
2361
  for await (const chunk of archive)
2353
2362
  parts.push(Buffer.from(chunk));
2354
- const gz = gzipSync(Buffer.concat(parts));
2363
+ // Off the event loop: the archive is a whole deploy artifact, and
2364
+ // compressing it synchronously stalled every other request this process
2365
+ // was serving for as long as the compression took.
2366
+ const gz = await gzipAsync(Buffer.concat(parts));
2355
2367
  const quotedPath = shellQuote(path);
2356
2368
  const failIfError = (result, step) => {
2357
2369
  if (result.exitCode !== 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-code-sandbox-flyio",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "Fly.io Machines (Firecracker microVM) code sandbox provider",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",