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 diff --git a/modules/module-mysql/src/replication/BinLogStream.ts b/modules/module-mysql/src/replication/BinLogStream.ts index d2480857f..07183cc84 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 { @@ -292,7 +292,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 +653,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); + } +}