mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
fixed server connection status bug
This commit is contained in:
parent
e2ea2809b6
commit
c9fefd14fd
@ -2,6 +2,8 @@ const connections = require('./connections');
|
||||
const socket = require('../utility/socket');
|
||||
const { fork } = require('child_process');
|
||||
const _ = require('lodash');
|
||||
const AsyncLock = require('async-lock');
|
||||
const lock = new AsyncLock();
|
||||
|
||||
module.exports = {
|
||||
opened: [],
|
||||
@ -22,6 +24,7 @@ module.exports = {
|
||||
handle_ping() {},
|
||||
|
||||
async ensureOpened(conid) {
|
||||
const res = await lock.acquire(conid, async () => {
|
||||
const existing = this.opened.find(x => x.conid == conid);
|
||||
if (existing) return existing;
|
||||
const connection = await connections.get({ conid });
|
||||
@ -50,6 +53,8 @@ module.exports = {
|
||||
});
|
||||
subprocess.send({ msgtype: 'connect', ...connection });
|
||||
return newOpened;
|
||||
});
|
||||
return res;
|
||||
},
|
||||
|
||||
close(conid, kill = true) {
|
||||
@ -82,10 +87,12 @@ module.exports = {
|
||||
|
||||
ping_meta: 'post',
|
||||
async ping({ connections }) {
|
||||
for (const conid of connections) {
|
||||
await Promise.all(
|
||||
connections.map(async conid => {
|
||||
const opened = await this.ensureOpened(conid);
|
||||
opened.subprocess.send({ msgtype: 'ping' });
|
||||
}
|
||||
})
|
||||
);
|
||||
return { status: 'ok' };
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user