mirror of
https://github.com/ONLYOFFICE/server.git
synced 2026-04-07 14:04:35 +08:00
Merge pull request '[bug] Enforce unconditional autocommit=1 per MySQL connection for data consistency; Fix bug 76588' (#59) from fix/bug-76588 into release/v9.1.0
Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/server/pulls/59
This commit is contained in:
@ -433,8 +433,7 @@
|
||||
},
|
||||
"mysqlExtraOptions": {
|
||||
"connectTimeout": 60000,
|
||||
"queryTimeout": 60000,
|
||||
"autoCommit": false
|
||||
"queryTimeout": 60000
|
||||
}
|
||||
},
|
||||
"redis": {
|
||||
|
||||
@ -34,7 +34,6 @@
|
||||
|
||||
const mysql = require('mysql2/promise');
|
||||
const connectorUtilities = require('./connectorUtilities');
|
||||
const operationContext = require('../../../Common/sources/operationContext');
|
||||
const config = require('config');
|
||||
|
||||
const configSql = config.get('services.CoAuthoring.sql');
|
||||
@ -59,25 +58,9 @@ if (configuration.queryTimeout) {
|
||||
queryTimeout = configuration.queryTimeout;
|
||||
delete configuration.queryTimeout;
|
||||
}
|
||||
let autoCommit = false;
|
||||
if (configuration.autoCommit !== undefined) {
|
||||
//delete to fix issue with invalid configuration option
|
||||
autoCommit = configuration.autoCommit;
|
||||
delete configuration.autoCommit;
|
||||
}
|
||||
|
||||
const pool = mysql.createPool(configuration);
|
||||
|
||||
// Set autocommit once per connection
|
||||
if (autoCommit === true) {
|
||||
pool.on('connection', async conn => {
|
||||
conn
|
||||
.promise()
|
||||
.query('SET autocommit=1')
|
||||
.catch(err => operationContext.global.logger.error('Failed to set autocommit=1:', err.message));
|
||||
});
|
||||
}
|
||||
|
||||
function sqlQuery(ctx, sqlCommand, callbackFunction, opt_noModifyRes = false, opt_noLog = false, opt_values = []) {
|
||||
return executeQuery(ctx, sqlCommand, opt_values, opt_noModifyRes, opt_noLog).then(
|
||||
result => callbackFunction?.(null, result),
|
||||
@ -90,6 +73,12 @@ async function executeQuery(ctx, sqlCommand, values = [], noModifyRes = false, n
|
||||
try {
|
||||
connection = await pool.getConnection();
|
||||
|
||||
// Ensure session autocommit=1 once per physical connection; avoids pool 'connection' race and per-query overhead
|
||||
if (!connection.__autocommitSet) {
|
||||
await connection.query('SET autocommit=1');
|
||||
connection.__autocommitSet = true;
|
||||
}
|
||||
|
||||
const result = await connection.query({sql: sqlCommand, timeout: queryTimeout, values});
|
||||
|
||||
let output;
|
||||
|
||||
Reference in New Issue
Block a user