@syncular/server-workers 0.32.0 → 0.32.1

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.
@@ -117,6 +117,7 @@ export class SyncularRealtimeHost {
117
117
  /** Sockets whose rehydration `hello` must be swallowed (already greeted at
118
118
  * the real upgrade — rehydration is transparent to the client). */
119
119
  #swallowHello = new Set();
120
+ #closedSockets = new WeakSet();
120
121
  /** Explicit FIFO: Durable Object events may interleave at `await`. */
121
122
  #partitionTail = Promise.resolve();
122
123
  constructor(state, db, config) {
@@ -221,7 +222,7 @@ export class SyncularRealtimeHost {
221
222
  * Actions share the partition FIFO with sync rounds.
222
223
  */
223
224
  async #handleAdmin(request, url) {
224
- this.#getHub();
225
+ const hub = this.#getHub();
225
226
  const partition = request.headers.get(REALTIME_ID_HEADER.partition);
226
227
  if (this.#admin === undefined || partition === null || partition === '') {
227
228
  const error = new SyncError('sync.invalid_request', 'forwarded admin request names no partition');
@@ -232,6 +233,8 @@ export class SyncularRealtimeHost {
232
233
  ...(request.headers.get(ADMIN_ACTIONS_HEADER) === '1'
233
234
  ? { authorizeActions: () => true }
234
235
  : {}),
236
+ ...(hub.onError !== undefined ? { onError: hub.onError } : {}),
237
+ ...(hub.mapError !== undefined ? { mapError: hub.mapError } : {}),
235
238
  });
236
239
  url.pathname = url.pathname.slice(ADMIN_DO_PATH.length);
237
240
  url.searchParams.set('partition', partition);
@@ -317,6 +320,8 @@ export class SyncularRealtimeHost {
317
320
  * the DO woke from hibernation and lost its in-memory map.
318
321
  */
319
322
  async #sessionFor(ws) {
323
+ if (this.#closedSockets.has(ws))
324
+ return undefined;
320
325
  const existing = this.#sessions.get(ws);
321
326
  if (existing !== undefined)
322
327
  return existing;
@@ -324,6 +329,11 @@ export class SyncularRealtimeHost {
324
329
  if (!isAttachment(attachment))
325
330
  return undefined;
326
331
  const session = await this.#connectSession(ws, attachment, true);
332
+ if (this.#closedSockets.has(ws)) {
333
+ session.close();
334
+ this.#swallowHello.delete(ws);
335
+ return undefined;
336
+ }
327
337
  this.#sessions.set(ws, session);
328
338
  return session;
329
339
  }
@@ -348,6 +358,7 @@ export class SyncularRealtimeHost {
348
358
  }
349
359
  /** Hibernation callback: the socket closed. */
350
360
  async webSocketClose(ws) {
361
+ this.#closedSockets.add(ws);
351
362
  const session = this.#sessions.get(ws);
352
363
  if (session !== undefined) {
353
364
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncular/server-workers",
3
- "version": "0.32.0",
3
+ "version": "0.32.1",
4
4
  "description": "Cloudflare Workers adapter for the Syncular sync server",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Benjamin Kniffler",
@@ -45,11 +45,11 @@
45
45
  "!dist/**/*.test.d.ts"
46
46
  ],
47
47
  "dependencies": {
48
- "@syncular/server": "0.32.0",
49
- "@syncular/server-hono": "0.32.0"
48
+ "@syncular/server": "0.32.1",
49
+ "@syncular/server-hono": "0.32.1"
50
50
  },
51
51
  "devDependencies": {
52
- "@syncular/core": "0.32.0",
52
+ "@syncular/core": "0.32.1",
53
53
  "miniflare": "4.20260701.0"
54
54
  }
55
55
  }
@@ -213,6 +213,7 @@ export class SyncularRealtimeHost {
213
213
  /** Sockets whose rehydration `hello` must be swallowed (already greeted at
214
214
  * the real upgrade — rehydration is transparent to the client). */
215
215
  readonly #swallowHello = new Set<WebSocketLike>();
216
+ readonly #closedSockets = new WeakSet<WebSocketLike>();
216
217
  /** Explicit FIFO: Durable Object events may interleave at `await`. */
217
218
  #partitionTail: Promise<void> = Promise.resolve();
218
219
 
@@ -350,7 +351,7 @@ export class SyncularRealtimeHost {
350
351
  * Actions share the partition FIFO with sync rounds.
351
352
  */
352
353
  async #handleAdmin(request: Request, url: URL): Promise<Response> {
353
- this.#getHub();
354
+ const hub = this.#getHub();
354
355
  const partition = request.headers.get(REALTIME_ID_HEADER.partition);
355
356
  if (this.#admin === undefined || partition === null || partition === '') {
356
357
  const error = new SyncError(
@@ -364,6 +365,8 @@ export class SyncularRealtimeHost {
364
365
  ...(request.headers.get(ADMIN_ACTIONS_HEADER) === '1'
365
366
  ? { authorizeActions: () => true }
366
367
  : {}),
368
+ ...(hub.onError !== undefined ? { onError: hub.onError } : {}),
369
+ ...(hub.mapError !== undefined ? { mapError: hub.mapError } : {}),
367
370
  });
368
371
  url.pathname = url.pathname.slice(ADMIN_DO_PATH.length);
369
372
  url.searchParams.set('partition', partition);
@@ -460,11 +463,17 @@ export class SyncularRealtimeHost {
460
463
  * the DO woke from hibernation and lost its in-memory map.
461
464
  */
462
465
  async #sessionFor(ws: WebSocketLike): Promise<RealtimeSession | undefined> {
466
+ if (this.#closedSockets.has(ws)) return undefined;
463
467
  const existing = this.#sessions.get(ws);
464
468
  if (existing !== undefined) return existing;
465
469
  const attachment = ws.deserializeAttachment();
466
470
  if (!isAttachment(attachment)) return undefined;
467
471
  const session = await this.#connectSession(ws, attachment, true);
472
+ if (this.#closedSockets.has(ws)) {
473
+ session.close();
474
+ this.#swallowHello.delete(ws);
475
+ return undefined;
476
+ }
468
477
  this.#sessions.set(ws, session);
469
478
  return session;
470
479
  }
@@ -492,6 +501,7 @@ export class SyncularRealtimeHost {
492
501
 
493
502
  /** Hibernation callback: the socket closed. */
494
503
  async webSocketClose(ws: WebSocketLike): Promise<void> {
504
+ this.#closedSockets.add(ws);
495
505
  const session = this.#sessions.get(ws);
496
506
  if (session !== undefined) {
497
507
  try {