diff options
author | Max <post@wickenrode.com> | 2015-05-01 02:08:48 +0200 |
---|---|---|
committer | Max <post@wickenrode.com> | 2015-05-01 02:08:48 +0200 |
commit | 80a2088f43bd3a901fb20d714318d4b5d3dc60a9 (patch) | |
tree | 1325fbf84467ac56789b9c10a947ef4772214736 /Source/SPConnectionHandler.m | |
parent | ace145be795f25dfa42080e459a63cc0c885a9fa (diff) | |
download | sequelpro-80a2088f43bd3a901fb20d714318d4b5d3dc60a9.tar.gz sequelpro-80a2088f43bd3a901fb20d714318d4b5d3dc60a9.tar.bz2 sequelpro-80a2088f43bd3a901fb20d714318d4b5d3dc60a9.zip |
Significantly reduce risk of a race condition in a certain setup (see #2107)
* Replaced a run loop sleep with a thread sleep as it was on a background thread where a) a regular sleep is fine, b) the run loop sleep did not seem to have any effect
* While we are at it, cut done some duplicate code
* Removed a redundant if()
Diffstat (limited to 'Source/SPConnectionHandler.m')
-rw-r--r-- | Source/SPConnectionHandler.m | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m index 80e9c3f5..c216142f 100644 --- a/Source/SPConnectionHandler.m +++ b/Source/SPConnectionHandler.m @@ -174,8 +174,12 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; if (![mySQLConnection isConnected]) { if (sshTunnel && !cancellingConnection) { - // If an SSH tunnel is running, temporarily block to allow the tunnel to register changes in state - [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + // This is a race condition we cannot fix "properly": + // For meaningful error handling we need to also consider the debug output from the SSH connection. + // The SSH debug output might be sligthly delayed though (flush, delegates, ...) or + // there might not even by any output at all (when it is purely a libmysql issue). + // TL;DR: No guaranteed events we could wait for, just trying our luck. + [NSThread sleepForTimeInterval:0.1]; // 100ms // If the state is connection refused, attempt the MySQL connection again with the host using the hostfield value. if ([sshTunnel state] == SPMySQLProxyForwardingFailed) { @@ -184,7 +188,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1"; [mySQLConnection connect]; if (![mySQLConnection isConnected]) { - [[NSRunLoop currentRunLoop] runMode:NSModalPanelRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.2]]; + [NSThread sleepForTimeInterval:0.1]; //100ms } } } |