Repository navigation
Description
Describe the bug
In Firefox, loading the PostGIS extension fails at random with RuntimeError: indirect call to null during CREATE EXTENSION postgis. A retry on a new instance (or a new clone()) usually succeeds. Chromium and Node never fail.
To Reproduce
A self-contained page (imports PGlite 0.6.1 and @electric-sql/pglite-postgis 0.3.1 from jsDelivr):
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>PGlite + PostGIS: "indirect call to null" in Firefox</title>
<style>body{font:15px/1.5 system-ui,sans-serif;max-width:860px;margin:2em auto;padding:0 1em}pre{background:#f4f4f4;padding:1em;white-space:pre-wrap}</style>
<h1>PGlite 0.6.1 + PostGIS 0.3.1: <code>RuntimeError: indirect call to null</code> in Firefox</h1>
<p>Each attempt opens a PGlite instance with the PostGIS extension, runs <code>CREATE EXTENSION postgis</code> and one PostGIS function, then closes it.
In Chromium every attempt succeeds. In Firefox a large share of attempts fail at random with <code>indirect call to null</code>, and a retry on a new instance usually succeeds.</p>
<p>Parameters: <code>?n=20</code> (attempts), <code>?mode=clone</code> (default: clone one base instance per attempt) or <code>?mode=fresh</code> (a new <code>PGlite.create()</code> per attempt).</p>
<pre id="o">running…</pre>
<script type="module">
import { PGlite } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/index.js";
import { postgis } from "https://cdn.jsdelivr.net/npm/@electric-sql/pglite-postgis@0.3.1/dist/index.js";
const q = new URLSearchParams(location.search);
const n = Number(q.get("n") ?? 20), mode = q.get("mode") ?? "clone";
const out = document.getElementById("o");
const log = (line) => { out.textContent += `\n${line}`; console.log(line); };
out.textContent = `${navigator.userAgent}\nmode=${mode} n=${n}`;
const SQL = "CREATE EXTENSION postgis; SELECT ST_AsText(ST_Buffer(ST_MakePoint(1, 2), 1, 2));";
const base = mode === "clone" ? await PGlite.create({ extensions: { postgis } }) : null;
const result = { ok: 0, failed: 0, errors: {}, firstFailure: null };
for (let i = 1; i <= n; i++) {
const t0 = performance.now();
const db = base ? await base.clone() : await PGlite.create({ extensions: { postgis } });
try {
await db.exec(SQL);
result.ok++;
log(`attempt ${i}: ok (${Math.round(performance.now() - t0)} ms)`);
} catch (e) {
result.failed++;
result.errors[e.message] = (result.errors[e.message] ?? 0) + 1;
result.firstFailure ??= String(e.stack ?? e).split("\n").slice(0, 12).join("\n");
log(`attempt ${i}: FAILED (${Math.round(performance.now() - t0)} ms): ${e.message}`);
} finally {
await db.close().catch(() => {});
}
}
window.result = result;
log(`\nsummary: ${result.ok} ok, ${result.failed} failed\n${JSON.stringify(result.errors)}`);
if (result.firstFailure) log(`\nfirst failure stack:\n${result.firstFailure}`);
log("done");
</script>
</html>Open it with ?mode=clone&n=20 (one base instance cloned per attempt) or ?mode=fresh&n=20 (a new PGlite.create() per attempt).
Results
| Browser, mode | Wasm prefs | OK | Failed |
|---|---|---|---|
| Firefox 161, clone | defaults | 6 | 14 |
| Firefox 161, fresh | defaults | 9 | 11 |
| Firefox 161, clone | javascript.options.wasm_optimizingjit = false (baseline only) |
10 | 10 |
| Firefox 161, clone | javascript.options.wasm_baselinejit = false (optimizing only) |
19 | 1 |
| Firefox 161, clone | javascript.options.wasm_lazy_tiering = false |
no result: the page made no progress for 20 minutes (not investigated) | |
| Chromium 159, clone | 20 | 0 | |
| Chromium 159, fresh | 20 | 0 |
20 attempts per row, headless browsers driven by puppeteer-core (Firefox) and Playwright (Chromium), Linux x86_64.
Every failure:
could not load library "/pglite/lib/postgresql/postgis-3.so": could not load dynamic lib: /pglite/lib/postgresql/postgis-3.so
RuntimeError: indirect call to null
First frames of the stack (CDN build, not symbolized):
O@https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/chunk-DFZEZSL3.js:1:11521
Oe@https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/chunk-DFZEZSL3.js:1:18272
…
@https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/chunk-GE4YWJAD.js line 1 > WebAssembly.Module:wasm-function[0]:0x0
@https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/pglite.wasm:wasm-function[11422]:0x565b8b
@https://cdn.jsdelivr.net/npm/@electric-sql/pglite@0.6.1/dist/pglite.wasm:wasm-function[3764]:0x22c9dc
Analysis
Disabling Firefox's baseline wasm compiler (javascript.options.wasm_baselinejit = false) almost removes the failures (1 of 20). Disabling the optimizing one does not help (10 of 20 still fail). Chromium never fails. That points to a SpiderMonkey bug in baseline-compiled code around the function-table entries the Emscripten dynamic linker writes when it loads postgis-3.so. Reported to Mozilla: https://bugzilla.mozilla.org/show_bug.cgi?id=2099628
Two questions for the PGlite side:
- Could the extension loader avoid the trigger? For example, build PostGIS without dynamic linking, or link it eagerly at instance creation instead of at the first
CREATE EXTENSION. - Until Firefox is fixed, would you take a retry, or a documented note for Firefox users?
Workaround
We retry on a new clone when the error message matches indirect call to null (up to 40 times). In our workload that is about 1.4 s per failed attempt, and 3 to 5 failures per analysis on average.
Environment
- PGlite 0.6.1 (PostgreSQL 19.0),
@electric-sql/pglite-postgis0.3.1 - Firefox 161.0 on Linux x86_64; Chromium 159 for comparison
Activity
[-]Firefox: PostGIS fails at random with `RuntimeError: indirect call to null`[/-][+][BUG]: Firefox: PostGIS fails at random with `RuntimeError: indirect call to null`[/+]Gheop commentedon Dec 1, 2026
More data: the same failure reproduces in a second, independent engine, deterministically.
Ladybird 2026.48.2 (LibWasm interpreter, no JIT), Linux x86_64, headless via its WebDriver, same
repro.htmlas above:CREATE EXTENSION postgisCREATE EXTENSION pgcrypto(also a dlopen()ed side module)Ladybird error, at the same point as Firefox (while loading
postgis-3.so):That is a
call_indirectto an uninitialized table element, the same condition Firefox reports asindirect call to null. The control page only swaps PostGIS for pgcrypto (CREATE EXTENSION pgcrypto; SELECT encode(digest('a', 'sha256'), 'hex');), so side-module loading works in general and the failure is specific topostgis-3.so.Two engines failing at the same call, only with PostGIS, while V8 never fails, suggests the PostGIS side module (or the order in which its table entries are filled during dlopen) may rely on behavior that V8 happens to tolerate, rather than a single engine bug. Ladybird's WebAssembly support is still incomplete, so this is a hint, not a proof. Its failure is deterministic, though, which may make it easier to debug than the intermittent Firefox case.
Gheop commentedon Dec 1, 2026
Root cause found. This is a race in how the extension's side modules are preloaded, not a browser engine bug. It explains Firefox (random), Ladybird (always) and Chromium (never).
What happens
loadExtensionsuntarspostgis.tar.gzand callsFS.createPreloadedFilefor each.sowithout awaiting the previous one, sopostgis-3.so,postgis_raster-3.soandpostgis_topology-3.sogo through Emscripten's wasm preload plugin (loadWebAssemblyModule(..., {loadAsync: true})) concurrently.WebAssembly.instantiatereads its imports, which creates the module'sGOT.mem/GOT.funcentries in the globalGOTwith value-1.postInstantiationrunsupdateGOT(exports)and thenreportUndefinedSymbols(). That function scans the whole globalGOT, including the-1entries of a sibling whose imports have been read but whosepostInstantiationhas not run yet. Those symbols are not resolvable yet, so it throws (TypeError: can't access property "value", _ is undefined).updateGOTregistered its exports in the GOT, and before__wasm_apply_data_relocsand__wasm_call_ctorsran.CREATE EXTENSION postgis,dlopeninstantiatespostgis-3.soagain.updateGOTkeeps the existing entries (value != -1), so the new instance resolves its own symbols to the zombie instance from step 4, whose data was never relocated. Its constructors call a function pointer that is still 0:indirect call to nullin Firefox,uninitialized elementin Ladybird.Whether this triggers depends only on the order in which the three compilations finish and on when each engine reads the imports, which explains the engine differences.
Loader log (local copy of PGlite 0.6.1 with logging added in
postInstantiation, the preload plugin,reportUndefinedSymbolsanddlopenInternal). Failing Firefox 161 attempt:Ladybird gives the same sequence on every attempt. Chromium always logs
preload okfor the three modules, in order. Firefox attempts where onlypostgis_raster-3orpostgis_topology-3fails to preload still succeed, because neither is dlopen()ed afterwards.Workaround, verified. Run the side-module instantiations one at a time, each starting only after the previous
postInstantiationhas run:Same
repro.html, with only this added before the imports:In Node, the cost is within noise (8.4 s vs 8.3 s for our end-to-end check of a PostGIS model).
Suggested fixes
.sofiles of the extension bundles sequentially (await eachcreatePreloadedFilebefore starting the next) instead of collecting the promises forPromise.all. That is the smallest change and removes the race for every multi-module extension, and also between bundles (e.g.postgistogether with a contrib extension).reportUndefinedSymbols()checks GOT entries belonging to other modules still in flight, and a failed load leaves its GOT entries pointing to an instance that was never relocated, which later loads then reuse.This also corrects my earlier comment: the module itself is fine, and the Ladybird data point was the same race with a deterministic order. I'm closing the Firefox bug (https://bugzilla.mozilla.org/show_bug.cgi?id=2099628) as not a SpiderMonkey issue.