Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion NativeScript/runtime/ModuleInternalCallbacks.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ bool HasPendingAsyncModuleGraphWork() {
// load's shared_ptr past teardown, so the slot destructor alone cannot cover
// these. Called from QuiesceModuleLoadsForIsolate.
static void KillAsyncGraphLoadsForIsolate(v8::Isolate* isolate) {
auto* state = ModuleLoaderStateFor(isolate);
// Runtime invalidates the Caches before quiescing, so StateFor would be null.
auto* state = Caches::ExistingStateFor<ModuleLoaderState>(isolate);
if (state == nullptr) {
return;
}
Expand Down
58 changes: 58 additions & 0 deletions TestRunner/app/tests/HttpEsmLoaderTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,64 @@ describe("HTTP ESM Loader", function() {
});
});

describe("worker teardown", function () {
var originalTimeout;
beforeEach(function () {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
});
afterEach(function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});

it("survives HTTP module fetches that land after their worker terminated",
function (done) {
var origin = getHostOrigin();
if (!origin) {
pending("REPORT_BASEURL not set; skipping host HTTP tests");
done();
return;
}
var workerDelayMs = 2000;
var workerCount = 5;
var remaining = workerCount;

// Delayed past every worker response, so by the time it
// settles all of them have arrived at their torn-down loaders.
function importOnMain() {
import(origin + "/esm/slow/leaf.mjs?k=wt-main&delayMs=" + (workerDelayMs + 1000))
.then(function (mod) {
expect(mod.value).toBe(42);
done();
}).catch(function (error) {
expect("rejected: " + formatError(error)).toBe("resolved");
done();
});
}

function settle(worker) {
worker.terminate();
if (--remaining === 0) {
importOnMain();
}
}

for (var i = 0; i < workerCount; i++) {
(function (worker, k) {
worker.onmessage = function () {
settle(worker);
};
worker.onerror = function (error) {
fail("worker " + k + " errored: " + formatError(error));
settle(worker);
};
worker.postMessage(origin + "/esm/slow/leaf.mjs?k=" + k +
"&delayMs=" + workerDelayMs);
})(new Worker("./httpImportTerminateWorker.js"), "wt" + i);
}
});
});

// The import map is process-wide, so every spec here installs its own
// and restores the empty map afterwards.
// Each present configureLoader section replaces its state wholesale, so
Expand Down
6 changes: 6 additions & 0 deletions TestRunner/app/tests/httpImportTerminateWorker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Starts an HTTP dynamic import and reports as soon as its fetch is in flight,
// without waiting for it to settle.
onmessage = function (msg) {
import(msg.data).catch(function () {});
postMessage("fetching");
};
Loading