Skip to content

Commit

Permalink
Prevent document unloading if active connections exist
Browse files Browse the repository at this point in the history
This change ensures that a document is not unloaded while it still has active connections. It adds a condition to check the connection count before proceeding with the unload process. This prevents potential disruptions for connected clients.
  • Loading branch information
janthurau committed Feb 20, 2025
1 parent e37b160 commit a46f2bb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/server/src/Hocuspocus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,10 @@ export class Hocuspocus {

await this.hooks('beforeUnloadDocument', { instance: this, documentName })

if (document.getConnectionsCount() > 0) {
return
}

this.documents.delete(documentName)
document.destroy()
await this.hooks('afterUnloadDocument', { instance: this, documentName })
Expand Down

0 comments on commit a46f2bb

Please sign in to comment.