Intermittent `RuntimeError: indirect call to null` when an Emscripten side module is dlopen()ed (PGlite + PostGIS); almost gone with the baseline compiler disabled
Categories
(Core :: JavaScript: WebAssembly, defect, P2)
Tracking
()
People
(Reporter: lizardonthestorm, Unassigned)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
|
2.51 KB,
text/html
|
Details |
Steps to reproduce
- Open the attached
repro.html(it imports PGlite 0.6.1 and its PostGIS 0.3.1 extension from jsDelivr), or serve it locally and openrepro.html?mode=clone&n=20. - The page runs 20 attempts. Each attempt opens a PGlite instance (PostgreSQL compiled to WebAssembly with Emscripten), runs
CREATE EXTENSION postgisand one PostGIS function, then closes the instance.CREATE EXTENSION postgismakes PostgreSQLdlopen()postgis-3.so, an Emscripten side module that is instantiated and linked into the main module's function table at that point.
Actual results
With default prefs, 14 of 20 attempts fail (clone mode) and 11 of 20 fail (fresh mode). Every failure has the same message:
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
The failing attempts throw RuntimeError: indirect call to null during CREATE EXTENSION postgis. Retrying on a new instance usually succeeds, so the failure looks timing-dependent.
Expected results
All attempts succeed, as they do in Chromium:
Chromium 159: 20 of 20 succeed in both modes.
Wasm tier prefs
| 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.
Disabling the optimizing compiler does not help (10 of 20 still fail), while disabling the baseline compiler almost removes the failures (1 of 20). The failing frame is wasm-function[0] of a module created at load time, called from the main module while PostgreSQL dlopen()s the side module. This points at code compiled by the baseline tier around dynamic linking (function-table entries written by the Emscripten loader), not at a real null pointer in PostgreSQL or PostGIS: the same build never fails in Chromium.
Environment
- Firefox 161.0, Linux x86_64 (Fedora, kernel 7.3), Intel Core Ultra 7 155H. Also seen in a normal (non-headless) Firefox window.
- PGlite 0.6.1 (PostgreSQL 19.0),
@electric-sql/pglite-postgis0.3.1.
Notes
- We work around it in our application by retrying on a fresh instance (up to 40 times). In a real workload this costs about 1.4 s per failed attempt, and up to 20 failed attempts have been observed for one analysis.
PGlite issue: https://github.com/electric-sql/pglite/issues/1254
Updated•3 days ago
|
Still reproducible on today's Nightly.
Firefox Nightly 163.0a1, BuildID 20261201090953 (mozilla-central d1919a12e7778f5c9dcf6bb0c787b43cc2fba1e3), Linux x86_64, default prefs, fresh profile, headless (puppeteer-core), attached repro.html, 20 attempts per mode:
| Build | clone | fresh |
|---|---|---|
| Nightly 163.0a1 | 13 of 20 failed | 16 of 20 failed |
| Release 161.0 (same machine, same run) | 12 of 20 failed | 14 of 20 failed |
All failures are RuntimeError: indirect call to null while dlopen()ing postgis-3.so, as in comment 0.
Not a SpiderMonkey bug: found the root cause, closing as INVALID. Sorry for the noise, and thanks for triaging.
PGlite preloads the three PostGIS side modules (postgis-3, postgis_raster-3, postgis_topology-3) concurrently through Emscripten's async wasm preload plugin. When one finishes, Emscripten's reportUndefinedSymbols() scans the whole global GOT, including entries of a sibling whose imports were already read but that is not instantiated yet. It throws, after the module's exports were registered in the GOT but before its data relocations and constructors ran. The later dlopen() of postgis-3.so reuses those GOT entries and calls a function pointer that was never relocated (still 0): "indirect call to null".
Whether it triggers depends on the order in which the compilations finish and on when the engine reads the imports. That explains why Firefox fails at random, why the result changes when the baseline compiler is disabled, why Chromium never fails, and why Ladybird fails every time ("uninitialized element").
Running the side-module instantiations one at a time fixes it: 0 of 40 failures in Firefox 161 and in Nightly 163.0a1, against 26 and 29 of 40 before. Details, loader logs and the workaround: https://github.com/electric-sql/pglite/issues/1254#issuecomment-7322790874
Description
•