@syncular/server-workers 0.21.1 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -289,20 +289,32 @@ export class SyncularRealtimeHost {
289
289
  if (session === undefined)
290
290
  return;
291
291
  if (typeof message === 'string') {
292
- await session.handleMessage(message);
292
+ session.handleMessage(message);
293
293
  }
294
294
  else {
295
295
  // §8.7: tagged binary — sync-round request chunks / acks.
296
296
  await session.handleBinary(new Uint8Array(message));
297
297
  }
298
+ // §8.2: an ack persists the cursor without being awaited inside the
299
+ // session. Drain it inside the hibernatable event so the DO never
300
+ // ends the event with storage work still in flight.
301
+ await session.drain();
298
302
  });
299
303
  }
300
304
  /** Hibernation callback: the socket closed. */
301
305
  async webSocketClose(ws) {
302
306
  const session = this.#sessions.get(ws);
303
307
  if (session !== undefined) {
304
- session.close();
305
- this.#sessions.delete(ws);
308
+ try {
309
+ // §8.2: a cursor write queued by the last ack may still be in flight.
310
+ // The failure must surface, but it must not skip the cleanup below —
311
+ // a leaked session keeps its presence and its map entry.
312
+ await session.drain();
313
+ }
314
+ finally {
315
+ session.close();
316
+ this.#sessions.delete(ws);
317
+ }
306
318
  }
307
319
  this.#swallowHello.delete(ws);
308
320
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server-workers",
3
- "version": "0.21.1",
3
+ "version": "0.23.0",
4
4
  "description": "Cloudflare Workers adapter for the Syncular sync server",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -45,10 +45,10 @@
45
45
  "!dist/**/*.test.d.ts"
46
46
  ],
47
47
  "dependencies": {
48
- "@syncular/server": "0.21.1",
49
- "@syncular/server-hono": "0.21.1"
48
+ "@syncular/server": "0.23.0",
49
+ "@syncular/server-hono": "0.23.0"
50
50
  },
51
51
  "devDependencies": {
52
- "@syncular/core": "0.21.1"
52
+ "@syncular/core": "0.23.0"
53
53
  }
54
54
  }
@@ -404,11 +404,15 @@ export class SyncularRealtimeHost {
404
404
  const session = await this.#sessionFor(ws);
405
405
  if (session === undefined) return;
406
406
  if (typeof message === 'string') {
407
- await session.handleMessage(message);
407
+ session.handleMessage(message);
408
408
  } else {
409
409
  // §8.7: tagged binary — sync-round request chunks / acks.
410
410
  await session.handleBinary(new Uint8Array(message));
411
411
  }
412
+ // §8.2: an ack persists the cursor without being awaited inside the
413
+ // session. Drain it inside the hibernatable event so the DO never
414
+ // ends the event with storage work still in flight.
415
+ await session.drain();
412
416
  });
413
417
  }
414
418
 
@@ -416,8 +420,15 @@ export class SyncularRealtimeHost {
416
420
  async webSocketClose(ws: WebSocketLike): Promise<void> {
417
421
  const session = this.#sessions.get(ws);
418
422
  if (session !== undefined) {
419
- session.close();
420
- this.#sessions.delete(ws);
423
+ try {
424
+ // §8.2: a cursor write queued by the last ack may still be in flight.
425
+ // The failure must surface, but it must not skip the cleanup below —
426
+ // a leaked session keeps its presence and its map entry.
427
+ await session.drain();
428
+ } finally {
429
+ session.close();
430
+ this.#sessions.delete(ws);
431
+ }
421
432
  }
422
433
  this.#swallowHello.delete(ws);
423
434
  }