mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-24 02:36:00 +00:00
handle errors when sending to subprocess #458
This commit is contained in:
@@ -140,7 +140,12 @@ module.exports = {
|
|||||||
const msgid = uuidv1();
|
const msgid = uuidv1();
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
this.requests[msgid] = [resolve, reject];
|
this.requests[msgid] = [resolve, reject];
|
||||||
conn.subprocess.send({ msgid, ...message });
|
try {
|
||||||
|
conn.subprocess.send({ msgid, ...message });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error sending request do process');
|
||||||
|
this.close(conn.conid, conn.database);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
@@ -289,6 +294,7 @@ module.exports = {
|
|||||||
if (existing) {
|
if (existing) {
|
||||||
existing.subprocess.send({ msgtype: 'ping' });
|
existing.subprocess.send({ msgtype: 'ping' });
|
||||||
} else {
|
} else {
|
||||||
|
// @ts-ignore
|
||||||
existing = await this.ensureOpened(conid, database);
|
existing = await this.ensureOpened(conid, database);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +325,13 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
const existing = this.opened.find(x => x.conid == conid && x.database == database);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing.disconnected = true;
|
existing.disconnected = true;
|
||||||
if (kill) existing.subprocess.kill();
|
if (kill) {
|
||||||
|
try {
|
||||||
|
existing.subprocess.kill();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error killing subprocess');
|
||||||
|
}
|
||||||
|
}
|
||||||
this.opened = this.opened.filter(x => x.conid != conid || x.database != database);
|
this.opened = this.opened.filter(x => x.conid != conid || x.database != database);
|
||||||
this.closed[`${conid}/${database}`] = {
|
this.closed[`${conid}/${database}`] = {
|
||||||
status: {
|
status: {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ const processArgs = require('../utility/processArgs');
|
|||||||
const { testConnectionPermission } = require('../utility/hasPermission');
|
const { testConnectionPermission } = require('../utility/hasPermission');
|
||||||
const { MissingCredentialsError } = require('../utility/exceptions');
|
const { MissingCredentialsError } = require('../utility/exceptions');
|
||||||
const pipeForkLogs = require('../utility/pipeForkLogs');
|
const pipeForkLogs = require('../utility/pipeForkLogs');
|
||||||
|
const { getLogger } = require('dbgate-tools');
|
||||||
|
|
||||||
|
const logger = getLogger('serverConnection');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
opened: [],
|
opened: [],
|
||||||
@@ -102,7 +105,13 @@ module.exports = {
|
|||||||
const existing = this.opened.find(x => x.conid == conid);
|
const existing = this.opened.find(x => x.conid == conid);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
existing.disconnected = true;
|
existing.disconnected = true;
|
||||||
if (kill) existing.subprocess.kill();
|
if (kill) {
|
||||||
|
try {
|
||||||
|
existing.subprocess.kill();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error killing subprocess');
|
||||||
|
}
|
||||||
|
}
|
||||||
this.opened = this.opened.filter(x => x.conid != conid);
|
this.opened = this.opened.filter(x => x.conid != conid);
|
||||||
this.closed[conid] = {
|
this.closed[conid] = {
|
||||||
...existing.status,
|
...existing.status,
|
||||||
@@ -152,7 +161,12 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
this.lastPinged[conid] = new Date().getTime();
|
this.lastPinged[conid] = new Date().getTime();
|
||||||
const opened = await this.ensureOpened(conid);
|
const opened = await this.ensureOpened(conid);
|
||||||
opened.subprocess.send({ msgtype: 'ping' });
|
try {
|
||||||
|
opened.subprocess.send({ msgtype: 'ping' });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error calling ping');
|
||||||
|
this.close(conid);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
return { status: 'ok' };
|
return { status: 'ok' };
|
||||||
@@ -189,7 +203,12 @@ module.exports = {
|
|||||||
const msgid = uuidv1();
|
const msgid = uuidv1();
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
this.requests[msgid] = [resolve, reject];
|
this.requests[msgid] = [resolve, reject];
|
||||||
conn.subprocess.send({ msgid, ...message });
|
try {
|
||||||
|
conn.subprocess.send({ msgid, ...message });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error sending request');
|
||||||
|
this.close(conn.conid);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ const uuidv1 = require('uuid/v1');
|
|||||||
const { handleProcessCommunication } = require('./processComm');
|
const { handleProcessCommunication } = require('./processComm');
|
||||||
const processArgs = require('../utility/processArgs');
|
const processArgs = require('../utility/processArgs');
|
||||||
const pipeForkLogs = require('./pipeForkLogs');
|
const pipeForkLogs = require('./pipeForkLogs');
|
||||||
|
const { getLogger } = require('dbgate-tools');
|
||||||
|
const logger = getLogger('DatastoreProxy');
|
||||||
|
|
||||||
class DatastoreProxy {
|
class DatastoreProxy {
|
||||||
constructor(file) {
|
constructor(file) {
|
||||||
@@ -68,7 +70,12 @@ class DatastoreProxy {
|
|||||||
const msgid = uuidv1();
|
const msgid = uuidv1();
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
this.requests[msgid] = [resolve, reject];
|
this.requests[msgid] = [resolve, reject];
|
||||||
this.subprocess.send({ msgtype: 'read', msgid, offset, limit });
|
try {
|
||||||
|
this.subprocess.send({ msgtype: 'read', msgid, offset, limit });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error getting rows');
|
||||||
|
this.subprocess = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
@@ -77,7 +84,12 @@ class DatastoreProxy {
|
|||||||
const msgid = uuidv1();
|
const msgid = uuidv1();
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
this.requests[msgid] = [resolve, reject];
|
this.requests[msgid] = [resolve, reject];
|
||||||
this.subprocess.send({ msgtype: 'notify', msgid });
|
try {
|
||||||
|
this.subprocess.send({ msgtype: 'notify', msgid });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error notifying subprocess');
|
||||||
|
this.subprocess = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return promise;
|
return promise;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,11 +33,15 @@ function callForwardProcess(connection, tunnelConfig, tunnelCacheKey) {
|
|||||||
);
|
);
|
||||||
pipeForkLogs(subprocess);
|
pipeForkLogs(subprocess);
|
||||||
|
|
||||||
subprocess.send({
|
try {
|
||||||
msgtype: 'connect',
|
subprocess.send({
|
||||||
connection,
|
msgtype: 'connect',
|
||||||
tunnelConfig,
|
connection,
|
||||||
});
|
tunnelConfig,
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error connecting SSH');
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
subprocess.on('message', resp => {
|
subprocess.on('message', resp => {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
|
const { getLogger } = require('dbgate-tools');
|
||||||
const uuidv1 = require('uuid/v1');
|
const uuidv1 = require('uuid/v1');
|
||||||
const { getSshTunnel } = require('./sshTunnel');
|
const { getSshTunnel } = require('./sshTunnel');
|
||||||
|
const logger = getLogger('sshTunnelProxy');
|
||||||
|
|
||||||
const dispatchedMessages = {};
|
const dispatchedMessages = {};
|
||||||
|
|
||||||
async function handleGetSshTunnelRequest({ msgid, connection }, subprocess) {
|
async function handleGetSshTunnelRequest({ msgid, connection }, subprocess) {
|
||||||
const response = await getSshTunnel(connection);
|
const response = await getSshTunnel(connection);
|
||||||
subprocess.send({ msgtype: 'getsshtunnel-response', msgid, response });
|
try {
|
||||||
|
subprocess.send({ msgtype: 'getsshtunnel-response', msgid, response });
|
||||||
|
} catch (err) {
|
||||||
|
logger.error({ err }, 'Error sending to SSH tunnel');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGetSshTunnelResponse({ msgid, response }, subprocess) {
|
function handleGetSshTunnelResponse({ msgid, response }, subprocess) {
|
||||||
|
|||||||
Reference in New Issue
Block a user