mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-19 17:46:00 +00:00
close chidl processes when parent exits
This commit is contained in:
@@ -27,7 +27,12 @@ module.exports = {
|
||||
},
|
||||
test(req, res) {
|
||||
const subprocess = fork(process.argv[1], ['connectProcess']);
|
||||
subprocess.on('message', (resp) => res.json(resp));
|
||||
subprocess.on('message', (resp) => {
|
||||
const { msgtype } = res;
|
||||
if (msgtype == 'connected' || msgtype == 'error') {
|
||||
res.json(resp);
|
||||
}
|
||||
});
|
||||
subprocess.send(req.body);
|
||||
},
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ module.exports = {
|
||||
resolve(response);
|
||||
delete this.requests[msgid];
|
||||
},
|
||||
handle_ping() {},
|
||||
|
||||
async ensureOpened(conid, database) {
|
||||
const existing = this.opened.find((x) => x.conid == conid && x.database == database);
|
||||
|
||||
@@ -14,6 +14,8 @@ module.exports = {
|
||||
handle_error(conid, { error }) {
|
||||
console.log(`Error in server connection ${conid}: ${error}`);
|
||||
},
|
||||
handle_ping() {
|
||||
},
|
||||
|
||||
async ensureOpened(conid) {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
|
||||
@@ -58,6 +58,8 @@ module.exports = {
|
||||
jsldata.notifyChangedStats(stats);
|
||||
},
|
||||
|
||||
handle_ping() {},
|
||||
|
||||
create_meta: 'post',
|
||||
async create({ conid, database }) {
|
||||
const sesid = uuidv1();
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
const engines = require('@dbgate/engines');
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
const childProcessChecker = require('../utility/childProcessChecker');
|
||||
|
||||
function start() {
|
||||
process.on('message', async connection => {
|
||||
childProcessChecker();
|
||||
process.on('message', async (connection) => {
|
||||
try {
|
||||
const driver = engines(connection);
|
||||
const conn = await driverConnect(driver, connection);
|
||||
const res = await driver.getVersion(conn);
|
||||
process.send(res);
|
||||
process.send({ msgtype: 'connected', ...res });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
process.send({ msgtype: 'error', error: e.message });
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const engines = require('@dbgate/engines');
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
const childProcessChecker = require('../utility/childProcessChecker');
|
||||
|
||||
let systemConnection;
|
||||
let storedConnection;
|
||||
@@ -67,6 +68,7 @@ async function handleMessage({ msgtype, ...other }) {
|
||||
}
|
||||
|
||||
function start() {
|
||||
childProcessChecker();
|
||||
process.on('message', async (message) => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const engines = require('@dbgate/engines');
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
const childProcessChecker = require('../utility/childProcessChecker');
|
||||
|
||||
let systemConnection;
|
||||
let storedConnection;
|
||||
@@ -29,7 +30,8 @@ async function handleMessage({ msgtype, ...other }) {
|
||||
}
|
||||
|
||||
function start() {
|
||||
process.on('message', async message => {
|
||||
childProcessChecker();
|
||||
process.on('message', async (message) => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
} catch (e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ const uuidv1 = require('uuid/v1');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const _ = require('lodash');
|
||||
const childProcessChecker = require('../utility/childProcessChecker');
|
||||
|
||||
const driverConnect = require('../utility/driverConnect');
|
||||
const { jsldir } = require('../utility/directories');
|
||||
@@ -132,6 +133,7 @@ async function handleMessage({ msgtype, ...other }) {
|
||||
}
|
||||
|
||||
function start() {
|
||||
childProcessChecker();
|
||||
process.on('message', async (message) => {
|
||||
try {
|
||||
await handleMessage(message);
|
||||
|
||||
17
packages/api/src/utility/childProcessChecker.js
Normal file
17
packages/api/src/utility/childProcessChecker.js
Normal file
@@ -0,0 +1,17 @@
|
||||
let counter = 0;
|
||||
|
||||
function childProcessChecker() {
|
||||
setInterval(() => {
|
||||
try {
|
||||
process.send({ msgtype: 'ping', counter: counter++ });
|
||||
} catch (ex) {
|
||||
// This will come once parent dies.
|
||||
// One way can be to check for error code ERR_IPC_CHANNEL_CLOSED
|
||||
// and call process.exit()
|
||||
console.log('parent died', ex.toString());
|
||||
process.exit();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
module.exports = childProcessChecker;
|
||||
Reference in New Issue
Block a user