From dd5c9e81ed3a3e7bee4a19bc177b3b069aa5df9d Mon Sep 17 00:00:00 2001 From: stanley2058 Date: Fri, 24 Jan 2025 00:59:33 +0800 Subject: [PATCH] fix: should check if namespace exist before trim --- src/y-socket-io/y-socket-io.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/y-socket-io/y-socket-io.js b/src/y-socket-io/y-socket-io.js index 1afa49b..0df9393 100644 --- a/src/y-socket-io/y-socket-io.js +++ b/src/y-socket-io/y-socket-io.js @@ -536,7 +536,17 @@ export class YSocketIO { } else { await this.client.store.persistDoc(namespace, 'index', doc) } - await this.client.trimRoomStream(namespace, 'index') + + /** + * there's a possibility where the namespace is deleted after the + * persist promise resolved, so we have to check if the room still + * exist. + * @see cleanupNamespace + * @see cleanupNamespaceImpl + */ + if (this.namespaceMap.has(namespace)) { + await this.client.trimRoomStream(namespace, 'index') + } } catch (e) { console.error(e) } finally {