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).
This commit is contained in:
Khushboo Vashi 2017-07-17 15:17:58 +01:00 committed by Dave Page
parent 3942461c50
commit c546182789
2 changed files with 44 additions and 17 deletions

View File

@ -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.
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) |
+--------------------------+--------------------+---------------------------------------------------------------+

View File

@ -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
{