diff --git a/.changeset/spicy-shirts-smoke.md b/.changeset/spicy-shirts-smoke.md new file mode 100644 index 0000000000..461199d06a --- /dev/null +++ b/.changeset/spicy-shirts-smoke.md @@ -0,0 +1,5 @@ +--- +"electric-sql": patch +--- + +Ensure no snapshot is taken after closing the Satellite process. diff --git a/clients/typescript/src/satellite/process.ts b/clients/typescript/src/satellite/process.ts index d05c91ee8a..f574282ebd 100644 --- a/clients/typescript/src/satellite/process.ts +++ b/clients/typescript/src/satellite/process.ts @@ -260,7 +260,7 @@ export class SatelliteProcess implements Satellite { ) // Starting now! - setTimeout(this._throttledSnapshot, 0) + await this._throttledSnapshot() // Need to reload primary keys after schema migration this.relations = await this._getLocalRelations() diff --git a/clients/typescript/test/satellite/process.test.ts b/clients/typescript/test/satellite/process.test.ts index d2c8e8198e..3768799dca 100644 --- a/clients/typescript/test/satellite/process.test.ts +++ b/clients/typescript/test/satellite/process.test.ts @@ -2262,3 +2262,27 @@ test("don't leave a snapshot running when stopping", async (t) => { t.pass() }) + +test("don't snapshot after closing satellite process", async (t) => { + // open and then immediately close + // check that no snapshot is called after close + const { satellite, authState, token } = t.context + const { connectionPromise } = await startSatellite( + satellite, + authState, + token + ) + + await connectionPromise + await satellite.stop() + + satellite._performSnapshot = () => { + t.fail('Snapshot was called') + return Promise.resolve(new Date()) + } + + // wait some time to see that mutexSnapshot is not called + await sleepAsync(50) + + t.pass() +})