Skip to content

Commit

Permalink
#4186 Disable client-side timeouts for connection (by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rider committed Sep 21, 2018
1 parent 32b8550 commit 98135cc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 11 deletions.
Expand Up @@ -797,7 +797,7 @@ pref_page_error_handle_name = Error handle
pref_page_error_handle_description = Error handle settings
pref_page_error_handle_group_timeouts_title = Timeouts (ms)
pref_page_error_handle_connection_open_timeout_label = Connection open
pref_page_error_handle_connection_open_timeout_label_tip = Connection opening timeout.\nIt is a UI timeout, real socket timeout can be configured in connection driver settings.
pref_page_error_handle_connection_open_timeout_label_tip = Connection opening timeout.\nClient-side timeout, real socket timeout can be configured in connection driver settings. Zero means disables timeout (wait until socket timeout).
pref_page_error_handle_connection_close_timeout_label = Connection close
pref_page_error_handle_connection_close_timeout_label_tip = Connection closing timeout.\nIt is a UI timeout, real socket timeout can be configured in connection driver settings.
pref_page_error_handle_connection_validate_timeout_label = Connection validation
Expand Down
Expand Up @@ -140,7 +140,7 @@ private static void initializeDefaultPreferences(DBPPreferenceStore store) {
PrefUtils.setDefaultPreferenceValue(store, EXECUTE_RECOVER_ENABLED, true);
PrefUtils.setDefaultPreferenceValue(store, EXECUTE_RECOVER_RETRY_COUNT, 1);

PrefUtils.setDefaultPreferenceValue(store, CONNECTION_OPEN_TIMEOUT, 20000);
PrefUtils.setDefaultPreferenceValue(store, CONNECTION_OPEN_TIMEOUT, 0);
PrefUtils.setDefaultPreferenceValue(store, CONNECTION_VALIDATION_TIMEOUT, 5000);
PrefUtils.setDefaultPreferenceValue(store, CONNECTION_CLOSE_TIMEOUT, 5000);

Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.jkiss.dbeaver.model.messages.ModelMessages;
import org.jkiss.dbeaver.model.meta.Property;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.model.runtime.DBRRunnableWithProgress;
import org.jkiss.dbeaver.model.runtime.VoidProgressMonitor;
import org.jkiss.dbeaver.model.sql.SQLDataSource;
import org.jkiss.dbeaver.model.sql.SQLDialect;
Expand Down Expand Up @@ -139,7 +140,7 @@ protected Connection openConnection(@NotNull DBRProgressMonitor monitor, JDBCRem
int openTimeout = getContainer().getPreferenceStore().getInt(ModelPreferences.CONNECTION_OPEN_TIMEOUT);
final Driver driverInstanceFinal = driverInstance;

boolean openTaskFinished = RuntimeUtils.runTask(monitor1 -> {
DBRRunnableWithProgress connectTask = monitor1 -> {
try {
if (driverInstanceFinal == null) {
connection[0] = DriverManager.getConnection(url, connectProps);
Expand All @@ -149,7 +150,14 @@ protected Connection openConnection(@NotNull DBRProgressMonitor monitor, JDBCRem
} catch (Exception e) {
error[0] = e;
}
}, "Opening database connection", openTimeout + 2000);
};
boolean openTaskFinished;
if (openTimeout <= 0) {
openTaskFinished = true;
connectTask.run(monitor);
} else {
openTaskFinished = RuntimeUtils.runTask(connectTask, "Opening database connection", openTimeout + 2000);
}
if (error[0] != null) {
throw error[0];
}
Expand Down
Expand Up @@ -217,15 +217,18 @@ protected IStatus run(DBRProgressMonitor monitor) {

// Wait for job to finish
long startTime = System.currentTimeMillis();
if (waitTime > 0) {
while (!monitoringTask.finished && System.currentTimeMillis() - startTime < waitTime) {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
break;
}
while (!monitoringTask.finished) {
if (waitTime > 0 && System.currentTimeMillis() - startTime > waitTime) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
log.debug("Task '" + taskName + "' was interrupted");
break;
}
}

return monitoringTask.finished;
}

Expand All @@ -243,6 +246,7 @@ public static void setThreadName(String name) {

private static class MonitoringTask implements DBRRunnableWithProgress {
private final DBRRunnableWithProgress task;
private DBRProgressMonitor monitor;
volatile boolean finished;

private MonitoringTask(DBRRunnableWithProgress task) {
Expand All @@ -255,6 +259,7 @@ public boolean isFinished() {

@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
this.monitor = monitor;
try {
task.run(monitor);
} finally {
Expand Down

0 comments on commit 98135cc

Please sign in to comment.