openvibers/openvibe.sdk Commits

SDK 0.35.1: a PGlite test database no longer keeps its process alive, and the containers' lease is unref'd only once it is held (#22)

OP OpenVibers committed 8 Oct 2026 · 23f9e95a80 · 9 files, +79 −11

Changes

ddiff --git a/CHANGELOG.md b/CHANGELOG.md
iindex 1b73c04..235e430 100644
---- a/CHANGELOG.md
++++ b/CHANGELOG.md
@@@ -3,6 +3,19 @@
All notable changes to `openvibe-sdk`. The package follows semver; while it is `0.x`, a minor
release may change an API and says so here.
++## 0.35.1 (2026-10-08)
++
++- **A PGlite test database no longer keeps its process alive (`openvibe-sdk/testing`, patch):** PGlite emulates
++ PostgreSQL's SIGALRM timers with `setTimeout` (its wasm runtime's `__setitimer_js`), and one loaded from a snapshot
++ (0.29.0) keeps rescheduling a 10 s startup-progress alarm, so a test file that ended without closing its database
++ never exited and a per-file runner timed it out (OpenVibe.Network's whole suite, OpenVibe.Community's unclosed
++ tests). `createTestDb` on PGlite now unrefs the timers `__setitimer_js` sets (told apart by the caller's frame, once
++ per process); queries run synchronously in the wasm and never wait on one. Every other timer, a test's own
++ included, stays ref'd. A service-side workaround that unrefs every PGlite timer (OpenVibe.Media's preload) can go.
++- **`createTestDb` on the containers unrefs its lease connection only once the lease is held (patch):** 0.31.1
++ unref'd the socket before `pg_advisory_lock` answered, so a process with nothing else open (no PGlite alarm since
++ the fix above) exited mid-setup with code 0, its remaining tests never run.
++
## 0.35.0 (2026-10-07)
- **Events public origin moves to `https://openvibe.events` (plan T7):** realtime clients and the mock
ddiff --git a/README.md b/README.md
iindex 7c9c85a..683c38d 100644
---- a/README.md
++++ b/README.md
@@@ -2,14 +2,14 @@
> Supported browser and server clients for the OpenVibe platform.
--**Status:** alpha, v0.35.0 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat and AI clients from WS-F task 4; per-actor limits from WS-R task 4). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
++**Status:** alpha, v0.35.1 (roadmap Wave 2; developer apps from Wave 20; Media objects v2 from Wave 4; the Tools platform API; Search, Chat and AI clients from WS-F task 4; per-actor limits from WS-R task 4). Every release is tagged (see [CHANGELOG.md](CHANGELOG.md)). Tested against local stub servers and the built-in mock platform only, never against the live platform. Services pin release tags; each repository's `STATUS.json` names the one it uses.
**Plan:** OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30.
**License:** MIT ([LICENSE](LICENSE)). This package is a library that apps outside the network embed, so it uses MIT. The OpenVibe services themselves stay AGPL-3.0.
**If a capability is not in the SDK, it is not public.** Apps call services through `openvibe-sdk` and never build internal routes themselves. A route with no SDK wrapper is internal, even when you can reach it, and it can change without notice. To make a capability public, first define it in OpenVibe.Contracts, then wrap it here.
```bash
--npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.35.0
++npm install https://codeload.github.com/OpenVibers/OpenVibe.SDK/tar.gz/refs/tags/v0.35.1
```
It has no runtime dependencies. It needs Node ≥ 20, or any browser with `fetch`, Web Crypto and `TextDecoder`. There is no build step. The package is CommonJS with ESM entry points (`import` works). Each subpath has its own `.d.ts`. For a page with no bundler, `browser/openvibe-sdk.mjs` is one self-contained ES module of the browser-safe subpaths (see [Browser without a bundler](#browser-without-a-bundler)). It does not depend on `openvibe-contracts` at runtime: it copies the contract types it uses (from Contracts v0.86.0, a devDependency the tests check them against).
ddiff --git a/STATUS.json b/STATUS.json
iindex c0ab720..55cd302 100644
---- a/STATUS.json
++++ b/STATUS.json
@@@ -3,7 +3,7 @@
"stage": "alpha",
"code": true,
"wave": "W2",
-- "version": "0.35.0",
++ "version": "0.35.1",
"plan": "OpenVibe End-to-End Realignment & Implementation Plan, revision 3 (20 Sep 2026), §3.2; roadmap §30",
"deployed": false,
"deployment": "none: a package released as git tags; services and apps pin a tag",
ddiff --git a/browser/openvibe-sdk.mjs b/browser/openvibe-sdk.mjs
iindex 9a44904..1e36e92 100644
---- a/browser/openvibe-sdk.mjs
++++ b/browser/openvibe-sdk.mjs
@@@ -1,4 +1,4 @@
--// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.35.0, MIT). Do not edit.
++// Generated by scripts/browser-bundle.js from browser.js (openvibe-sdk 0.35.1, MIT). Do not edit.
// One self-contained ES module: core at the top level plus the browser-safe subpaths as namespaces
// (auth, registry, modules, realtime, media, community, bot, search, chat, ai, jobs, tools, projects, geo). No server-only code: no service tokens, JWT verification, events, identity.
/* eslint-disable */
@@@ -42,7 +42,7 @@ const { paginate, offsetPager } = __load(7);
const semver = __load(6);
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.35.0';
++const SDK_VERSION = '0.35.1';
module.exports = {
createClient,
ddiff --git a/package-lock.json b/package-lock.json
iindex 26350fc..d58148a 100644
---- a/package-lock.json
++++ b/package-lock.json
@@@ -1,12 +1,12 @@
{
"name": "openvibe-sdk",
-- "version": "0.35.0",
++ "version": "0.35.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "openvibe-sdk",
-- "version": "0.35.0",
++ "version": "0.35.1",
"license": "MIT",
"devDependencies": {
"@electric-sql/pglite": "^0.5.8",
ddiff --git a/package.json b/package.json
iindex 0a9e9ab..4e33378 100644
---- a/package.json
++++ b/package.json
@@@ -1,6 +1,6 @@
{
"name": "openvibe-sdk",
-- "version": "0.35.0",
++ "version": "0.35.1",
"description": "Supported browser and server clients for the OpenVibe platform: auth (incl. developer apps), registry discovery, identity, user modules, events, realtime, media, community, Bot robots, search, chat, AI runs, Tools (registry, run API and jobs), VIP memberships and developer projects, the async PostgreSQL data layer (db) and the Valkey cache, limits store, queue and pub/sub, with deadlines, safe retries, problem errors and trace propagation.",
"main": "index.js",
"types": "types/index.d.ts",
ddiff --git a/src/core/index.js b/src/core/index.js
iindex ddc41a3..c2add68 100644
---- a/src/core/index.js
++++ b/src/core/index.js
@@@ -8,7 +8,7 @@ const { paginate, offsetPager } = require('./paginate');
const semver = require('./semver');
/** The package version (test/version.test.js keeps it equal to package.json). */
--const SDK_VERSION = '0.35.0';
++const SDK_VERSION = '0.35.1';
module.exports = {
createClient,
ddiff --git a/src/testing/db.js b/src/testing/db.js
iindex 64b8ba0..c64a789 100644
---- a/src/testing/db.js
++++ b/src/testing/db.js
@@@ -122,8 +122,35 @@ function pruneSnapshots(dir, keep) {
}
}
++/**
++ * PGlite emulates PostgreSQL's SIGALRM timers (startup progress, statement and lock timeouts) with setTimeout from
++ * its wasm runtime's __setitimer_js. A PGlite loaded from a data directory (a snapshot hit) keeps rescheduling a
++ * 10 s startup-progress alarm, so a test that ends without closing its database never exits and a per-file runner
++ * times it out. Queries run synchronously in the wasm and never wait on an alarm, so those timers are unref'd: the
++ * first PGlite test database of a process wraps setTimeout once, and every other timer (a test's own) stays ref'd.
++ */
++let alarmsUnrefd = false;
++function unrefPgliteAlarms() {
++ if (alarmsUnrefd) return;
++ alarmsUnrefd = true;
++ const real = globalThis.setTimeout;
++ const fromAlarm = () => {
++ const limit = Error.stackTraceLimit;
++ Error.stackTraceLimit = 3; // the wrapper, then its caller: enough to see __setitimer_js, and cheap
++ try { return String(new Error().stack || '').includes('__setitimer_js'); } finally { Error.stackTraceLimit = limit; }
++ };
++ const wrapped = function setTimeout(...args) {
++ const h = real.apply(this, args);
++ if (h && typeof h.unref === 'function' && fromAlarm()) h.unref();
++ return h;
++ };
++ Object.defineProperties(wrapped, Object.getOwnPropertyDescriptors(real)); // util.promisify.custom and the rest
++ globalThis.setTimeout = wrapped;
++}
++
async function pgliteTestDb({ migrations, seed, seedKey, service, log }) {
const { createDb } = require('../db');
++ unrefPgliteAlarms();
const t0 = Date.now();
const handle = (db, snapshot) => ({
db, store: 'pglite', snapshot, setupMs: Date.now() - t0, url: null, directUrl: null, open: null, close: () => db.close().catch(() => {}),
@@@ -209,10 +236,12 @@ async function createTestDb({ migrations, seed, seedKey, store = process.env.OV_
let releasingLease = false;
try {
await lease.connect();
++ await lease.query('SELECT pg_advisory_lock($1::bigint)', [leaseKey(name)]);
// The lease socket must not keep the process alive: a test file that ends without process.exit() would otherwise
-- // never exit (0.26-0.31.0). It still holds the advisory lock for as long as the process lives.
++ // never exit (0.26-0.31.0). It still holds the advisory lock for as long as the process lives. Unref'd only once
++ // the lock is held: a query pending on an unref'd socket lets a process with nothing else open exit mid-setup
++ // (0.31.1-0.35.0, hidden while a PGlite alarm kept test processes open).
if (lease.connection && lease.connection.stream && typeof lease.connection.stream.unref === 'function') lease.connection.stream.unref();
-- await lease.query('SELECT pg_advisory_lock($1::bigint)', [leaseKey(name)]);
lease.on('end', () => { if (!releasingLease) throw new Error(`test database lease lost for ${name}`); });
const database = await su.value('SELECT current_database()');
await sweepOrphans(su).catch(() => {}); // what killed runs left behind; never in the way of this run
ddiff --git a/test/testing-db.test.js b/test/testing-db.test.js
iindex 534ca1e..351b921 100644
---- a/test/testing-db.test.js
++++ b/test/testing-db.test.js
@@@ -119,6 +119,32 @@ const { createTestDb } = require(${JSON.stringify(path.join(__dirname, '..', 'sr
try { assert.equal(t.snapshot, 'built'); } finally { await t.close(); }
assert.deepEqual(leftovers(), []);
}],
++ ['snapshot: a test that never closes its database still exits (PGlite\'s alarm timers are unref\'d)', async () => {
++ const m = migrationsDir('CREATE TABLE left_open (id int);');
++ const first = await createTestDb({ migrations: m, service: 'sdk' }); await first.close(); // the snapshot exists now
++ const script = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'sdk-testdb-child-')), 'open.js');
++ fs.writeFileSync(script, `'use strict';
++const { createTestDb } = require(${JSON.stringify(path.join(__dirname, '..', 'src', 'testing', 'db'))});
++(async () => {
++ const t = await createTestDb({ migrations: process.argv[2], service: 'sdk' });
++ await t.db.query('INSERT INTO left_open VALUES (1)');
++ const n = await t.db.value('SELECT count(*)::int FROM left_open');
++ await new Promise((r) => setTimeout(r, 300)); // a test's own timer still runs: ref'd as ever
++ process.send({ snapshot: t.snapshot, n });
++})().catch((e) => { process.send({ error: e.message }); process.exit(1); });
++`);
++ const child = fork(script, [m], { stdio: ['ignore', 'ignore', 'inherit', 'ipc'] });
++ const t0 = Date.now();
++ let msg = null;
++ child.on('message', (x) => { msg = x; });
++ const code = await new Promise((resolve) => {
++ const kill = setTimeout(() => { child.kill('SIGKILL'); resolve('still running after 30 s'); }, 30000);
++ child.on('exit', (c) => { clearTimeout(kill); resolve(c); });
++ });
++ assert.deepEqual(msg, { snapshot: 'hit', n: 1 });
++ assert.equal(code, 0, 'the child exited by itself');
++ assert.ok(Date.now() - t0 < 9000, `without waiting out the 10 s alarm (${Date.now() - t0} ms)`);
++ }],
['snapshot: OV_TEST_SNAPSHOT=0 migrates every time and writes nothing', async () => {
const m = migrationsDir('CREATE TABLE off (id int);');
process.env.OV_TEST_SNAPSHOT = '0';