From b91c5be93ffc5a906e15935dc844d25bc5df8da2 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Wed, 12 Mar 2025 14:36:44 +0200 Subject: [PATCH 1/3] Avoid hiding original error on rollback error. --- .../module-mysql/src/replication/BinLogStream.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/module-mysql/src/replication/BinLogStream.ts b/modules/module-mysql/src/replication/BinLogStream.ts index d2480857f..554e62892 100644 --- a/modules/module-mysql/src/replication/BinLogStream.ts +++ b/modules/module-mysql/src/replication/BinLogStream.ts @@ -136,7 +136,7 @@ export class BinLogStream { await this.snapshotTable(connection.connection, batch, result.table); await promiseConnection.query('COMMIT'); } catch (e) { - await promiseConnection.query('ROLLBACK'); + await tryRollback(promiseConnection); throw e; } } finally { @@ -273,6 +273,7 @@ AND table_type = 'BASE TABLE';`, ); await promiseConnection.query('START TRANSACTION'); await promiseConnection.query(`SET time_zone = '+00:00'`); + await this.connections.end(); const sourceTables = this.syncRules.getSourceTables(); await this.storage.startBatch( @@ -292,7 +293,7 @@ AND table_type = 'BASE TABLE';`, logger.info(`Initial replication done`); await promiseConnection.query('COMMIT'); } catch (e) { - await promiseConnection.query('ROLLBACK'); + await tryRollback(promiseConnection); throw e; } finally { connection.release(); @@ -653,3 +654,11 @@ AND table_type = 'BASE TABLE';`, } } } + +async function tryRollback(promiseConnection: mysqlPromise.Connection) { + try { + await promiseConnection.query('ROLLBACK'); + } catch (e) { + logger.error('Failed to rollback transaction', e); + } +} From 1bc9367e5da663a73b24691f0a83ca60e0ccc34a Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Wed, 12 Mar 2025 14:41:14 +0200 Subject: [PATCH 2/3] Add changeset. --- .changeset/fuzzy-items-look.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/fuzzy-items-look.md diff --git a/.changeset/fuzzy-items-look.md b/.changeset/fuzzy-items-look.md new file mode 100644 index 000000000..50318de5b --- /dev/null +++ b/.changeset/fuzzy-items-look.md @@ -0,0 +1,7 @@ +--- +'@powersync/service-module-mysql': patch +'@powersync/service-core': patch +'@powersync/service-image': patch +--- + +[MySQL] Fix errors being hidden by ROLLBACK failure From 9562d9e0a6bed00aee8866fade3199a03e688d49 Mon Sep 17 00:00:00 2001 From: Ralf Kistner Date: Wed, 12 Mar 2025 14:41:32 +0200 Subject: [PATCH 3/3] Remove test code. --- modules/module-mysql/src/replication/BinLogStream.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/module-mysql/src/replication/BinLogStream.ts b/modules/module-mysql/src/replication/BinLogStream.ts index 554e62892..07183cc84 100644 --- a/modules/module-mysql/src/replication/BinLogStream.ts +++ b/modules/module-mysql/src/replication/BinLogStream.ts @@ -273,7 +273,6 @@ AND table_type = 'BASE TABLE';`, ); await promiseConnection.query('START TRANSACTION'); await promiseConnection.query(`SET time_zone = '+00:00'`); - await this.connections.end(); const sourceTables = this.syncRules.getSourceTables(); await this.storage.startBatch(