fix: Unhandled connection in closed state
gitea/mylogger/pipeline/head This commit looks good
Details
gitea/mylogger/pipeline/head This commit looks good
Details
This commit is contained in:
parent
4e709c2091
commit
5857c2294e
33
mylogger.js
33
mylogger.js
|
@ -57,12 +57,9 @@ module.exports = class MyLogger {
|
|||
async init() {
|
||||
const {conf} = this;
|
||||
this.debug('MyLogger', 'Initializing.');
|
||||
this.onErrorListener = err => this.onError(err);
|
||||
|
||||
// DB connection
|
||||
|
||||
const db = this.db = await mysql.createConnection(conf.dstDb);
|
||||
db.on('error', this.onErrorListener);
|
||||
|
||||
await this.modelLoader.loadSchema();
|
||||
await this.showDb.loadSchema();
|
||||
|
@ -135,8 +132,6 @@ module.exports = class MyLogger {
|
|||
this.running = false;
|
||||
this.debug('MyLogger', 'Ending.');
|
||||
|
||||
this.db.off('error', this.onErrorListener);
|
||||
|
||||
clearInterval(this.flushInterval);
|
||||
clearInterval(this.pingInterval);
|
||||
clearInterval(this.flushTimeout);
|
||||
|
@ -206,7 +201,6 @@ module.exports = class MyLogger {
|
|||
zongji.once('error', onError);
|
||||
zongji.start(zongjiOpts);
|
||||
});
|
||||
zongji.on('error', this.onErrorListener);
|
||||
this.zongji = zongji;
|
||||
this.debug('Zongji', 'Started.');
|
||||
}
|
||||
|
@ -220,7 +214,6 @@ module.exports = class MyLogger {
|
|||
this.zongji = null;
|
||||
|
||||
zongji.off('binlog', this.onBinlogListener);
|
||||
zongji.off('error', this.onErrorListener);
|
||||
|
||||
// FIXME: Cannot call Zongji.stop(), it doesn't wait to end connection
|
||||
zongji.connection.destroy(() => {
|
||||
|
@ -250,7 +243,7 @@ module.exports = class MyLogger {
|
|||
}
|
||||
}
|
||||
|
||||
async onError(err) {
|
||||
async handleError(err) {
|
||||
if (!this.isOk) return;
|
||||
this.isOk = false;
|
||||
console.log(`Error: ${err.code}: ${err.message}`);
|
||||
|
@ -259,19 +252,19 @@ module.exports = class MyLogger {
|
|||
await this.end(true);
|
||||
} catch(e) {}
|
||||
|
||||
switch (err.code) {
|
||||
case 'PROTOCOL_CONNECTION_LOST':
|
||||
case 'ECONNRESET':
|
||||
console.log('Trying to restart process.');
|
||||
// FIXME: Error of mysql2/promise
|
||||
if (err.message === `Can't add new command when connection is in closed state`)
|
||||
await this.tryRestart();
|
||||
break;
|
||||
default:
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
handleError(err) {
|
||||
console.error(err);
|
||||
else
|
||||
switch (err.code) {
|
||||
case 'PROTOCOL_CONNECTION_LOST':
|
||||
case 'ECONNRESET':
|
||||
console.log('Trying to restart process.');
|
||||
await this.tryRestart();
|
||||
break;
|
||||
default:
|
||||
process.exit();
|
||||
}
|
||||
}
|
||||
|
||||
async onBinlog(evt) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "mylogger",
|
||||
"version": "1.1.4",
|
||||
"version": "1.1.5",
|
||||
"author": "Verdnatura Levante SL",
|
||||
"description": "MySQL and MariaDB logger using binary log",
|
||||
"license": "GPL-3.0",
|
||||
|
|
Loading…
Reference in New Issue