diff --git a/.changeset/perfect-plums-cry.md b/.changeset/perfect-plums-cry.md new file mode 100644 index 000000000..b35b3c950 --- /dev/null +++ b/.changeset/perfect-plums-cry.md @@ -0,0 +1,5 @@ +--- +'@powersync/service-module-mysql': patch +--- + +Resolved excessive memory consumption during MySQL initial replication. diff --git a/modules/module-mysql/src/replication/BinLogStream.ts b/modules/module-mysql/src/replication/BinLogStream.ts index 483f292f9..bf1b24a75 100644 --- a/modules/module-mysql/src/replication/BinLogStream.ts +++ b/modules/module-mysql/src/replication/BinLogStream.ts @@ -305,12 +305,16 @@ AND table_type = 'BASE TABLE';`, columns = toColumnDescriptors(fields); }); - for await (let row of query.stream()) { + for await (let row of stream) { + if (this.stopped) { + throw new Error('Abort signal received - initial replication interrupted.'); + } + if (columns == null) { throw new Error(`No 'fields' event emitted`); } - const record = common.toSQLiteRow(row, columns!); + const record = common.toSQLiteRow(row, columns!); await batch.save({ tag: storage.SaveOperationTag.INSERT, sourceTable: table,