From c5461827894bc99a9d4909c078397a30a53dfee5 Mon Sep 17 00:00:00 2001 From: Khushboo Vashi Date: Mon, 17 Jul 2017 15:17:58 +0100 Subject: [PATCH] Modify the runtime to use time-based timeouts rather than retry based. Fixes #2556 This allows for slow vs. fast connection failures (e.g. an active rejection vs. no response). --- docs/en_US/desktop_deployment.rst | 27 ++++++++++++++++++++---- runtime/pgAdmin4.cpp | 34 +++++++++++++++++++------------ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/docs/en_US/desktop_deployment.rst b/docs/en_US/desktop_deployment.rst index 9765c778a..9f2515a18 100644 --- a/docs/en_US/desktop_deployment.rst +++ b/docs/en_US/desktop_deployment.rst @@ -57,7 +57,7 @@ In order to configure the Python code, follow these steps: $ python setup.py -Alternatively, you can simply run ``pgAdmin4.py`` at this point or aat a later time, +Alternatively, you can simply run ``pgAdmin4.py`` at this point or at a later time, and ``pgadmin4.db`` will be created automatically at first run. Runtime @@ -73,6 +73,25 @@ semi-colon character, for example: /Users/dpage/.virtualenvs/pgadmin4/lib/python2.7/site-packages/;/Users/dpage/python-libs/ -The configuration settings are stored using the QSettings class in Qt, which -will use an INI file on Unix systems, a plist file on Mac OS X, and the registry -on Windows. The Python Path setting is stored in the ``PythonPath`` key. \ No newline at end of file +The configuration settings are stored using the QSettings class in Qt, which +will use an INI file on Unix systems (~/.config/pgadmin/pgadmin4.conf), +a plist file on Mac OS X (~/Library/Preferences/org.pgadmin.pgadmin4.plist), +and the registry on Windows (HKEY_CURRENT_USER\\Software\\pgadmin\\pgadmin4). + +The configuration settings: + ++--------------------------+--------------------+---------------------------------------------------------------+ +| Key | Type | Purpose | ++==========================+====================+===============================================================+ +| ApplicationPath | String | The directory containing pgAdmin4.py | ++--------------------------+--------------------+---------------------------------------------------------------+ +| ConnectionTimeout | Integer | The number of seconds to wait for application server startup. | ++--------------------------+--------------------+---------------------------------------------------------------+ +| PythonPath | String | The Python module search path | ++--------------------------+--------------------+---------------------------------------------------------------+ +| Browser/Geometry | Binary | The runtime window's size/shape | ++--------------------------+--------------------+---------------------------------------------------------------+ +| Browser/WindowState | Binary | The runtime window's state | ++--------------------------+--------------------+---------------------------------------------------------------+ +| Browser/Zoom | String | The runtime window's zoom level (zoom % / 100) | ++--------------------------+--------------------+---------------------------------------------------------------+ \ No newline at end of file diff --git a/runtime/pgAdmin4.cpp b/runtime/pgAdmin4.cpp index 9054e9e65..d91bd665a 100644 --- a/runtime/pgAdmin4.cpp +++ b/runtime/pgAdmin4.cpp @@ -340,30 +340,38 @@ int main(int argc, char * argv[]) // Generate the app server URL QString appServerUrl = QString("http://127.0.0.1:%1/?key=%2").arg(port).arg(key); + // Read the server connection timeout from the registry or set the default timeout. + QSettings settings; + int timeout = settings.value("ConnectionTimeout", 30).toInt(); + // Now the server should be up, we'll attempt to connect and get a response. // We'll retry in a loop a few time before aborting if necessary. - int attempt = 0; - while (attempt++ < 50) + + QTime endTime = QTime::currentTime().addSecs(timeout); + bool alive = false; + + while(QTime::currentTime() <= endTime) { - bool alive = PingServer(QUrl(appServerUrl)); + alive = PingServer(QUrl(appServerUrl)); if (alive) { break; } - if (attempt == 50) - { - splash->finish(NULL); - QString error(QWidget::tr("The application server could not be contacted.")); - QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); - - exit(1); - } - delay(200); } + // Attempt to connect one more time in case of a long network timeout while looping + if(!alive && !PingServer(QUrl(appServerUrl))) + { + splash->finish(NULL); + QString error(QWidget::tr("The application server could not be contacted.")); + QMessageBox::critical(NULL, QString(QWidget::tr("Fatal Error")), error); + + exit(1); + } + // Create & show the main window BrowserWindow browserWindow(appServerUrl); browserWindow.setWindowTitle(PGA_APP_NAME); @@ -394,7 +402,7 @@ bool PingServer(QUrl url) QNetworkReply *reply; QVariant redirectUrl; - url.setPath("/misc/ping"); + url.setPath("/misc/pingx"); do {