Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

core: fix rejected sync chunks being marked as synced (#10533)

Abdullah Atta4748d4c0c11f
diff --git a/packages/core/src/api/sync/__tests__/collector.test.js b/packages/core/src/api/sync/__tests__/collector.test.js
index 026b18cb5..70c34dc81 100644
--- a/packages/core/src/api/sync/__tests__/collector.test.js
+++ b/packages/core/src/api/sync/__tests__/collector.test.js
@@ -326,6 +326,24 @@ test("sync should correctly select key based on keyVersion", () =>
}
}));
+test("chunks rejected by the server should not be marked as synced", () =>
+ databaseTest().then(async (db) => {
+ await loginFakeUser(db);
+ const { Sync } = await import("../index.ts");
+ const sync = new Sync(db);
+ sync.uploadAttachments = async () => {};
+ sync.pushItem = async () => false;
+
+ const noteId = await db.notes.add(TEST_NOTE);
+
+ await expect(sync.send("device")).rejects.toThrow(
+ /Failed to send all items/
+ );
+
+ expect((await db.notes.note(noteId)).synced).toBe(false);
+ expect(await new Collector(db).hasUnsyncedChanges()).toBe(true);
+ }));
+
async function iteratorToArray(iterator) {
let items = [];
for await (const item of iterator) {
diff --git a/packages/core/src/api/sync/index.ts b/packages/core/src/api/sync/index.ts
index fd6de5ad5..66a34d98e 100644
--- a/packages/core/src/api/sync/index.ts
+++ b/packages/core/src/api/sync/index.ts
@@ -290,6 +290,8 @@ export class Sync {
this.logger.error(
new Error(`Failed to send batch. Server returned falsy response.`)
);
+ // stop here so the collector doesn't mark the rejected items as synced
+ break;
}
}
this.logger.info(