@makoai/app-sdk 2.14.0 → 2.14.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/index.js +68 -31
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -36,7 +36,7 @@ import {
|
|
|
36
36
|
* in a page (or this export) says which SDK a deployed app actually runs.
|
|
37
37
|
* Kept in step with package.json by snapshot.test.mjs.
|
|
38
38
|
*/
|
|
39
|
-
export const SDK_VERSION = "2.14.
|
|
39
|
+
export const SDK_VERSION = "2.14.1";
|
|
40
40
|
if (typeof window !== "undefined") {
|
|
41
41
|
try {
|
|
42
42
|
window.__MAKO_APP_SDK__ = SDK_VERSION;
|
|
@@ -113,7 +113,7 @@ function getDb() {
|
|
|
113
113
|
// the default database, uncompressed.
|
|
114
114
|
await conn.query("ATTACH ':memory:' AS mako_tables (COMPRESS)");
|
|
115
115
|
} finally {
|
|
116
|
-
await conn.close();
|
|
116
|
+
await conn.close().catch(() => {});
|
|
117
117
|
}
|
|
118
118
|
} catch (error) {
|
|
119
119
|
// A failed boot retries with a new worker: end this one.
|
|
@@ -326,30 +326,11 @@ async function downloadBinding(name, bust, report) {
|
|
|
326
326
|
const what = 'Data for binding "' + name + '" could not be loaded';
|
|
327
327
|
report({ phase: "requesting", rowsWritten: null, bytes: null, bytesTotal: null });
|
|
328
328
|
// A slot holds the connection, not the wait for a build: one slow warehouse
|
|
329
|
-
// query must not hold up twelve bindings that are ready.
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
);
|
|
335
|
-
let signed = null;
|
|
336
|
-
if (isProgressResponse(res)) {
|
|
337
|
-
let final;
|
|
338
|
-
try {
|
|
339
|
-
final = await readProgressStream(res, e => report(progressPatch(e)));
|
|
340
|
-
} catch (error) {
|
|
341
|
-
// A cut build stream may have cost a warehouse query. Asking again costs another.
|
|
342
|
-
throw new Error(what + ": the build's stream was cut (" + (error instanceof Error ? error.message : String(error)) + ")");
|
|
343
|
-
}
|
|
344
|
-
if (final.phase === "failed") throw progressError(final, what);
|
|
345
|
-
report({ phase: "downloading", rowsWritten: null, bytes: 0 });
|
|
346
|
-
// No url: the server streams the bytes itself — the same path, asked
|
|
347
|
-
// plainly, serves them (the build already staged or cached them).
|
|
348
|
-
signed = final.url || path;
|
|
349
|
-
res = null;
|
|
350
|
-
}
|
|
351
|
-
return withSlot(async () => {
|
|
352
|
-
res ??= await fetchRetrying(signed);
|
|
329
|
+
// query must not hold up twelve bindings that are ready. A plain answer is read
|
|
330
|
+
// inside the slot that fetched it. Its body holds a connection, and over HTTP/1.1
|
|
331
|
+
// (6 per host, `vite dev`) queueing that body behind fetches waiting for one
|
|
332
|
+
// stalled Web Performance for good.
|
|
333
|
+
const readPlain = async res => {
|
|
353
334
|
if (!res.ok) throw await responseError(res, what);
|
|
354
335
|
try {
|
|
355
336
|
return await readBytes(res, (bytes, bytesTotal) =>
|
|
@@ -359,7 +340,26 @@ async function downloadBinding(name, bust, report) {
|
|
|
359
340
|
if (error instanceof TypeError) error.retry = "network"; // the body cut off: no build behind it
|
|
360
341
|
throw error;
|
|
361
342
|
}
|
|
343
|
+
};
|
|
344
|
+
const first = await withSlot(async () => {
|
|
345
|
+
const res = await fetchRetrying(path + (bust ? "?refresh=" + Date.now() : ""), {
|
|
346
|
+
headers: { accept: PROGRESS_ACCEPT },
|
|
347
|
+
});
|
|
348
|
+
return isProgressResponse(res) ? { stream: res } : { bytes: await readPlain(res) };
|
|
362
349
|
});
|
|
350
|
+
if (!first.stream) return first.bytes;
|
|
351
|
+
let final;
|
|
352
|
+
try {
|
|
353
|
+
final = await readProgressStream(first.stream, e => report(progressPatch(e)));
|
|
354
|
+
} catch (error) {
|
|
355
|
+
// A cut build stream may have cost a warehouse query. Asking again costs another.
|
|
356
|
+
throw new Error(what + ": the build's stream was cut (" + (error instanceof Error ? error.message : String(error)) + ")");
|
|
357
|
+
}
|
|
358
|
+
if (final.phase === "failed") throw progressError(final, what);
|
|
359
|
+
report({ phase: "downloading", rowsWritten: null, bytes: 0 });
|
|
360
|
+
// No url: the server streams the bytes itself — the same path, asked
|
|
361
|
+
// plainly, serves them (the build already staged or cached them).
|
|
362
|
+
return withSlot(async () => readPlain(await fetchRetrying(final.url || path)));
|
|
363
363
|
}
|
|
364
364
|
|
|
365
365
|
// ---------------------------------------------------------------------------
|
|
@@ -465,6 +465,24 @@ function catalog(fn) {
|
|
|
465
465
|
return run;
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
// A trap in close() must not replace the query's own answer or error: a finally
|
|
469
|
+
// that throws wins over the catch, and the panel showed raw "null function".
|
|
470
|
+
// Nor may a close wait forever: on a trapped worker it can stay pending until
|
|
471
|
+
// restartEngine terminates that worker, and then it never settles. The hook and
|
|
472
|
+
// the query around it stayed counted in `busy` for the page's life, so every
|
|
473
|
+
// later release was skipped.
|
|
474
|
+
const CLOSE_WAIT_MS = 1000;
|
|
475
|
+
async function closeConn(conn, engine) {
|
|
476
|
+
let timer;
|
|
477
|
+
try {
|
|
478
|
+
await Promise.race([conn.close(), new Promise(resolve => (timer = setTimeout(resolve, CLOSE_WAIT_MS)))]);
|
|
479
|
+
} catch (error) {
|
|
480
|
+
markEngineError(error, engine);
|
|
481
|
+
} finally {
|
|
482
|
+
clearTimeout(timer);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
|
|
468
486
|
// The statements in one transaction, so another connection never sees the
|
|
469
487
|
// name missing between a DROP and a CREATE.
|
|
470
488
|
async function exec(engine, statements) {
|
|
@@ -485,7 +503,7 @@ async function exec(engine, statements) {
|
|
|
485
503
|
} catch (error) {
|
|
486
504
|
throw markEngineError(error, engine);
|
|
487
505
|
} finally {
|
|
488
|
-
await conn
|
|
506
|
+
await closeConn(conn, engine);
|
|
489
507
|
}
|
|
490
508
|
}
|
|
491
509
|
|
|
@@ -590,7 +608,7 @@ async function estimateTable(engine, file, parquetBytes) {
|
|
|
590
608
|
} catch {
|
|
591
609
|
/* no metadata to read: the file's own error surfaces when it is read */
|
|
592
610
|
} finally {
|
|
593
|
-
await conn
|
|
611
|
+
await closeConn(conn, engine);
|
|
594
612
|
}
|
|
595
613
|
return parquetBytes * 16;
|
|
596
614
|
}
|
|
@@ -636,7 +654,7 @@ async function duckdbBytes(engine) {
|
|
|
636
654
|
markEngineError(error, engine);
|
|
637
655
|
return null; /* the OOM retry still applies */
|
|
638
656
|
} finally {
|
|
639
|
-
await conn
|
|
657
|
+
await closeConn(conn, engine);
|
|
640
658
|
}
|
|
641
659
|
}
|
|
642
660
|
|
|
@@ -1133,7 +1151,7 @@ export async function withConnection(fn) {
|
|
|
1133
1151
|
try {
|
|
1134
1152
|
return await fn(conn);
|
|
1135
1153
|
} finally {
|
|
1136
|
-
await conn
|
|
1154
|
+
await closeConn(conn, db);
|
|
1137
1155
|
}
|
|
1138
1156
|
} finally {
|
|
1139
1157
|
busy--;
|
|
@@ -1402,7 +1420,25 @@ async function runSql(sql, rowLimit, format, reads) {
|
|
|
1402
1420
|
}
|
|
1403
1421
|
}
|
|
1404
1422
|
|
|
1423
|
+
// The first query to trap an engine is its culprit: the others in flight only
|
|
1424
|
+
// failed because the engine was already gone. Twice first means it traps every
|
|
1425
|
+
// engine it runs on, so it stops running. Without this a mounted panel reruns on
|
|
1426
|
+
// each restart, traps that engine too and takes every other panel down with it,
|
|
1427
|
+
// until the 3 restarts are spent and the page stays dead. A changed query is a
|
|
1428
|
+
// different string, so a new filter still runs.
|
|
1429
|
+
const CULPRIT_LIMIT = 2;
|
|
1430
|
+
const culprits = new Map();
|
|
1431
|
+
let blamedEngine = null;
|
|
1432
|
+
function blameFirstTrap(sql, error, engine) {
|
|
1433
|
+
if (!crashedEngineError(error) || blamedEngine === engine) return;
|
|
1434
|
+
blamedEngine = engine;
|
|
1435
|
+
culprits.set(sql, (culprits.get(sql) ?? 0) + 1);
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1405
1438
|
async function runSqlOnce(sql, rowLimit, format) {
|
|
1439
|
+
if ((culprits.get(sql) ?? 0) >= CULPRIT_LIMIT) {
|
|
1440
|
+
throw new Error("This query crashed the data engine twice, so it stopped running. Change the filter or reload the page.");
|
|
1441
|
+
}
|
|
1406
1442
|
const cap = rowLimit === null ? Infinity : (rowLimit ?? DEFAULT_ROW_LIMIT);
|
|
1407
1443
|
const writes = !isReadOnlySql(sql);
|
|
1408
1444
|
if (writes) keepEngine(); // CREATE TABLE journal_t: only this worker has it
|
|
@@ -1423,9 +1459,10 @@ async function runSqlOnce(sql, rowLimit, format) {
|
|
|
1423
1459
|
const { rows, fields } = toPlainRows(table, cap);
|
|
1424
1460
|
return { rows, fields, rowCount, truncated: rowCount > rows.length };
|
|
1425
1461
|
} catch (error) {
|
|
1462
|
+
blameFirstTrap(sql, error, db);
|
|
1426
1463
|
throw markEngineError(error, db);
|
|
1427
1464
|
} finally {
|
|
1428
|
-
await conn
|
|
1465
|
+
await closeConn(conn, db);
|
|
1429
1466
|
}
|
|
1430
1467
|
} finally {
|
|
1431
1468
|
busy--;
|