From 7a7683488ff34fc79ae0de4432f7ca4a9cbcda20 Mon Sep 17 00:00:00 2001 From: mastertyko <11311479+mastertyko@users.noreply.github.com> Date: Mon, 13 Apr 2026 12:48:49 +0200 Subject: [PATCH] fix(gsd): disable db mmap on darwin (#4029) --- src/resources/extensions/gsd/gsd-db.ts | 2 +- .../extensions/gsd/tests/gsd-db.test.ts | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/resources/extensions/gsd/gsd-db.ts b/src/resources/extensions/gsd/gsd-db.ts index a088e04d6..333d5536d 100644 --- a/src/resources/extensions/gsd/gsd-db.ts +++ b/src/resources/extensions/gsd/gsd-db.ts @@ -169,7 +169,7 @@ function initSchema(db: DbAdapter, fileBacked: boolean): void { if (fileBacked) db.exec("PRAGMA synchronous = NORMAL"); if (fileBacked) db.exec("PRAGMA auto_vacuum = INCREMENTAL"); if (fileBacked) db.exec("PRAGMA cache_size = -8000"); // 8 MB page cache - if (fileBacked) db.exec("PRAGMA mmap_size = 67108864"); // 64 MB mmap + if (fileBacked && process.platform !== "darwin") db.exec("PRAGMA mmap_size = 67108864"); // 64 MB mmap db.exec("PRAGMA temp_store = MEMORY"); db.exec("PRAGMA foreign_keys = ON"); diff --git a/src/resources/extensions/gsd/tests/gsd-db.test.ts b/src/resources/extensions/gsd/tests/gsd-db.test.ts index 0987b9ad3..97c799421 100644 --- a/src/resources/extensions/gsd/tests/gsd-db.test.ts +++ b/src/resources/extensions/gsd/tests/gsd-db.test.ts @@ -43,6 +43,16 @@ function cleanup(dbPath: string): void { } } +function withPlatform(platform: NodeJS.Platform, fn: () => T): T { + const original = process.platform; + Object.defineProperty(process, 'platform', { value: platform }); + try { + return fn(); + } finally { + Object.defineProperty(process, 'platform', { value: original }); + } +} + // ═══════════════════════════════════════════════════════════════════════════ // gsd-db tests // ═══════════════════════════════════════════════════════════════════════════ @@ -279,6 +289,26 @@ describe('gsd-db', () => { cleanup(dbPath); }); + test('gsd-db: mmap stays disabled on darwin file-backed DBs', () => { + const darwinDbPath = tempDbPath(); + withPlatform('darwin', () => { + openDatabase(darwinDbPath); + const adapter = _getAdapter()!; + const mmap = adapter.prepare('PRAGMA mmap_size').get(); + assert.deepStrictEqual(mmap?.['mmap_size'], 0, 'darwin should leave mmap_size disabled'); + cleanup(darwinDbPath); + }); + + const linuxDbPath = tempDbPath(); + withPlatform('linux', () => { + openDatabase(linuxDbPath); + const adapter = _getAdapter()!; + const mmap = adapter.prepare('PRAGMA mmap_size').get(); + assert.deepStrictEqual(mmap?.['mmap_size'], 67108864, 'non-darwin should still enable mmap_size'); + cleanup(linuxDbPath); + }); + }); + test('gsd-db: transaction rollback on error', () => { openDatabase(':memory:');