Skip to content

Commit 282f262

Browse files
mejo-max-nextcloud
authored andcommitted
fix(sync): Only send recovery step in case of SyncStep1
Signed-off-by: Jonas <jonas@freesources.org>
1 parent 24ab61a commit 282f262

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

src/services/WebSocketPolyfill.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: AGPL-3.0-or-later
44
*/
55

6+
import { decodeArrayBuffer, encodeArrayBuffer } from '../helpers/base64'
67
import { logger } from '../helpers/logger.js'
7-
import { decodeArrayBuffer } from '../helpers/base64'
88
import getNotifyBus from './NotifyService.js'
99
import type { Step, Session, SyncService } from './SyncService'
1010

@@ -76,16 +76,24 @@ export default function initWebSocketPolyfill(syncService: SyncService, fileId:
7676
send(step: Uint8Array<ArrayBufferLike>) {
7777
// Useful for debugging what steps are sent and how they were initiated
7878
// logStep(step)
79-
if (this.#processingVersion) {
80-
// this is a direct response while processing the step
81-
console.error(`Failed to process step ${this.#processingVersion}.`, {
82-
lastSuccessfullyProcessed: syncService.version,
83-
sendingSyncStep1: step,
84-
})
85-
// Do not increase the syncService.version for the current steps
86-
// as we failed to process them.
87-
this.#processingVersion = 0
79+
80+
const encoded = encodeArrayBuffer(step)
81+
const isSyncStep1 = encoded < 'AAE'
82+
if (!this.#processingVersion || !isSyncStep1) {
83+
syncService.sendStep(step)
84+
return
8885
}
86+
87+
// If `this.#processingVersion` is set, we're in the middle of applying steps of one version.
88+
// If `isSyncStep1`, Yjs failed to integrate a message due to pending structs.
89+
// Log and ask for recovery due to a not applied/missing step.
90+
console.error(`Failed to process step ${this.#processingVersion}.`, {
91+
lastSuccessfullyProcessed: syncService.version,
92+
sendingSyncStep1: step,
93+
})
94+
// Do not increase the syncService.version for the current steps
95+
// as we failed to process them.
96+
this.#processingVersion = 0
8997
syncService.sendRecoveryStep(step)
9098
}
9199

0 commit comments

Comments
 (0)