mysql2 3.17.0 → 3.17.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/base/pool.js +43 -4
- package/package.json +2 -2
package/lib/base/pool.js
CHANGED
|
@@ -6,6 +6,22 @@ const EventEmitter = require('events').EventEmitter;
|
|
|
6
6
|
const PoolConnection = require('../pool_connection.js');
|
|
7
7
|
const Queue = require('denque');
|
|
8
8
|
const BaseConnection = require('./connection.js');
|
|
9
|
+
const Errors = require('../constants/errors.js');
|
|
10
|
+
|
|
11
|
+
// Source: https://github.com/go-sql-driver/mysql/blob/76c00e35a8d48f8f70f0e7dffe584692bd3fa612/packets.go#L598-L613
|
|
12
|
+
function isReadOnlyError(err) {
|
|
13
|
+
if (!err || !err.errno) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
// 1792: ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION
|
|
17
|
+
// 1290: ER_OPTION_PREVENTS_STATEMENT (returned by Aurora during failover)
|
|
18
|
+
// 1836: ER_READ_ONLY_MODE
|
|
19
|
+
return (
|
|
20
|
+
err.errno === Errors.ER_OPTION_PREVENTS_STATEMENT ||
|
|
21
|
+
err.errno === Errors.ER_CANT_EXECUTE_IN_READ_ONLY_TRANSACTION ||
|
|
22
|
+
err.errno === Errors.ER_READ_ONLY_MODE
|
|
23
|
+
);
|
|
24
|
+
}
|
|
9
25
|
|
|
10
26
|
function spliceConnection(queue, connection) {
|
|
11
27
|
const len = queue.length;
|
|
@@ -146,8 +162,24 @@ class BasePool extends EventEmitter {
|
|
|
146
162
|
return;
|
|
147
163
|
}
|
|
148
164
|
try {
|
|
165
|
+
let queryError = null;
|
|
166
|
+
const origOnResult = cmdQuery.onResult;
|
|
167
|
+
if (origOnResult) {
|
|
168
|
+
cmdQuery.onResult = function (err, rows, fields) {
|
|
169
|
+
queryError = err || null;
|
|
170
|
+
origOnResult(err, rows, fields);
|
|
171
|
+
};
|
|
172
|
+
} else {
|
|
173
|
+
cmdQuery.once('error', (err) => {
|
|
174
|
+
queryError = err;
|
|
175
|
+
});
|
|
176
|
+
}
|
|
149
177
|
conn.query(cmdQuery).once('end', () => {
|
|
150
|
-
|
|
178
|
+
if (isReadOnlyError(queryError)) {
|
|
179
|
+
conn.destroy();
|
|
180
|
+
} else {
|
|
181
|
+
conn.release();
|
|
182
|
+
}
|
|
151
183
|
});
|
|
152
184
|
} catch (e) {
|
|
153
185
|
conn.release();
|
|
@@ -169,9 +201,16 @@ class BasePool extends EventEmitter {
|
|
|
169
201
|
return cb(err);
|
|
170
202
|
}
|
|
171
203
|
try {
|
|
172
|
-
conn
|
|
173
|
-
|
|
174
|
-
|
|
204
|
+
conn
|
|
205
|
+
.execute(sql, values, (err, rows, fields) => {
|
|
206
|
+
if (isReadOnlyError(err)) {
|
|
207
|
+
conn.destroy();
|
|
208
|
+
}
|
|
209
|
+
cb(err, rows, fields);
|
|
210
|
+
})
|
|
211
|
+
.once('end', () => {
|
|
212
|
+
conn.release();
|
|
213
|
+
});
|
|
175
214
|
} catch (e) {
|
|
176
215
|
conn.release();
|
|
177
216
|
return cb(e);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mysql2",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.2",
|
|
4
4
|
"description": "fast mysql driver. Implements core protocol, prepared statements, ssl and compression in native JS",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "typings/mysql/index",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"lru.min": "^1.1.3",
|
|
61
61
|
"named-placeholders": "^1.1.6",
|
|
62
62
|
"seq-queue": "^0.0.5",
|
|
63
|
-
"sql-escaper": "^1.3.
|
|
63
|
+
"sql-escaper": "^1.3.3"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
66
|
"@eslint/eslintrc": "^3.3.3",
|