Skip to content

Fix missing atomicity in server commits #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions src/server/PatchesServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,19 @@ export class PatchesServer {
})
.filter(Boolean) as Change[];

// Persist the newly transformed changes
// Persist and notify about newly transformed changes atomically
if (transformedChanges.length > 0) {
await this.store.saveChanges(docId, transformedChanges);
}

// Fire event for realtime transports (WebSocket, etc.)
if (transformedChanges.length > 0) {
await this.onChangesCommitted.emit(docId, transformedChanges, originClientId);

try {
// Fire event for realtime transports (WebSocket, etc.)
await this.onChangesCommitted.emit(docId, transformedChanges, originClientId);
} catch (error) {
// If notification fails after saving, log error but don't fail the operation
// The changes are already committed to storage, so we can't roll back
console.error(`Failed to notify clients about committed changes for doc ${docId}:`, error);
// Consider implementing a retry mechanism or dead letter queue here
}
}

// Return committed changes and newly transformed changes separately
Expand Down