mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Fix orphan database connections resulting in an inability to connect to databases. #5567
This commit is contained in:
@@ -626,7 +626,8 @@ def utils():
|
||||
is_admin=current_user.has_role("Administrator"),
|
||||
login_url=login_url,
|
||||
username=current_user.username,
|
||||
auth_source=auth_source
|
||||
auth_source=auth_source,
|
||||
heartbeat_timeout=config.SERVER_HEARTBEAT_TIMEOUT
|
||||
),
|
||||
200, {'Content-Type': MIMETYPE_APP_JS})
|
||||
|
||||
|
||||
@@ -786,6 +786,10 @@ define('pgadmin.node.server', [
|
||||
if(data.errmsg) {
|
||||
Notify.error(data.errmsg);
|
||||
}
|
||||
// Generate the event that server is connected
|
||||
pgBrowser.Events.trigger(
|
||||
'pgadmin:server:connected', data._id, item, data
|
||||
);
|
||||
}
|
||||
})
|
||||
.fail(function(xhr, status, error) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import Notify, {initializeModalProvider, initializeNotifier} from '../../../stat
|
||||
import { checkMasterPassword } from '../../../static/js/Dialogs/index';
|
||||
import { pgHandleItemError } from '../../../static/js/utils';
|
||||
import { Search } from './quick_search/trigger_search';
|
||||
import { send_heartbeat } from './heartbeat';
|
||||
|
||||
define('pgadmin.browser', [
|
||||
'sources/gettext', 'sources/url_for', 'require', 'jquery',
|
||||
@@ -581,6 +582,10 @@ define('pgadmin.browser', [
|
||||
.fail(function() {/*This is intentional (SonarQube)*/});
|
||||
}, 300000);
|
||||
|
||||
obj.Events.on(
|
||||
'pgadmin:server:connected', send_heartbeat.bind(obj)
|
||||
);
|
||||
|
||||
obj.set_master_password('');
|
||||
obj.check_corrupted_db_file();
|
||||
obj.Events.on('pgadmin:browser:tree:add', obj.onAddTreeNode.bind(obj));
|
||||
|
||||
31
web/pgadmin/browser/static/js/heartbeat.js
Normal file
31
web/pgadmin/browser/static/js/heartbeat.js
Normal file
@@ -0,0 +1,31 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import gettext from 'sources/gettext';
|
||||
import url_for from 'sources/url_for';
|
||||
import getApiInstance from '../../../static/js/api_instance';
|
||||
import Notifier from '../../../static/js/helpers/Notifier';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
const axiosApi = getApiInstance();
|
||||
let HEARTBEAT_TIMEOUT = pgAdmin.heartbeat_timeout * 1000;
|
||||
|
||||
export function send_heartbeat(_server_id) {
|
||||
// Send heartbeat to the server every 30 seconds
|
||||
setInterval(function() {
|
||||
axiosApi.post(url_for('misc.heartbeat'), {'sid': _server_id})
|
||||
.then(() => {
|
||||
// pass
|
||||
})
|
||||
.catch((error) => {
|
||||
Notifier.error(gettext(`pgAdmin server not responding, try to login again: ${error.message || error.response.data.errormsg}`));
|
||||
});
|
||||
|
||||
}, HEARTBEAT_TIMEOUT);
|
||||
}
|
||||
@@ -66,6 +66,9 @@ define('pgadmin.browser.utils',
|
||||
/* GET the pgadmin server's locale */
|
||||
pgAdmin['pgadmin_server_locale'] = '{{pgadmin_server_locale}}';
|
||||
|
||||
/* Server Heartbeat Timeout */
|
||||
pgAdmin['heartbeat_timeout'] = '{{heartbeat_timeout}}';
|
||||
|
||||
// Define list of nodes on which Query tool option doesn't appears
|
||||
let unsupported_nodes = pgAdmin.unsupported_nodes = [
|
||||
'server_group', 'server', 'coll-tablespace', 'tablespace',
|
||||
|
||||
Reference in New Issue
Block a user