aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-05-26 14:58:41 +0000
committerrowanbeentje <rowan@beent.je>2012-05-26 14:58:41 +0000
commit813dc14be27f3abfba07ad99480988298bed0438 (patch)
treea68c19fc2030d9857db896eb15e2a4b1576d2f0e /Source
parentf17020da37a509e94795f8c9a73e95a02433eed8 (diff)
downloadsequelpro-813dc14be27f3abfba07ad99480988298bed0438.tar.gz
sequelpro-813dc14be27f3abfba07ad99480988298bed0438.tar.bz2
sequelpro-813dc14be27f3abfba07ad99480988298bed0438.zip
- Improve handling of MySQL connection cancellation, particularly when closing the associated window to prevent crashes
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConnectionHandler.m55
1 files changed, 28 insertions, 27 deletions
diff --git a/Source/SPConnectionHandler.m b/Source/SPConnectionHandler.m
index bd03a8e0..aec8a61e 100644
--- a/Source/SPConnectionHandler.m
+++ b/Source/SPConnectionHandler.m
@@ -130,7 +130,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1";
[mySQLConnection connect];
if (![mySQLConnection isConnected]) {
- if (sshTunnel) {
+ 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]];
@@ -149,26 +149,28 @@ static NSString *SPLocalhostAddress = @"127.0.0.1";
}
if (![mySQLConnection isConnected]) {
- NSString *errorMessage = @"";
- if (sshTunnel && [sshTunnel state] == SPMySQLProxyForwardingFailed) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection lastErrorMessage]];
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"SSH port forwarding failed", @"title when ssh tunnel port forwarding failed") errorMessage:errorMessage detail:[sshTunnel debugMessages]];
- }
- else if ([mySQLConnection lastErrorID] == 1045) { // "Access denied" error
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because access was denied.\n\nDouble-check your username and password and ensure that access from your current location is permitted.\n\nMySQL said: %@", @"message of panel when connection to host failed due to access denied error"), [self host], [mySQLConnection lastErrorMessage]];
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Access denied!", @"connection failed due to access denied title") errorMessage:errorMessage detail:nil];
- }
- else if ([self type] == SPSocketConnection && (![self socket] || ![[self socket] length]) && ![mySQLConnection socketPath]) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The socket file could not be found in any common location. Please supply the correct socket location.\n\nMySQL said: %@", @"message of panel when connection to socket failed because optional socket could not be found"), [mySQLConnection lastErrorMessage]];
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket not found!", @"socket not found title") errorMessage:errorMessage detail:nil];
- }
- else if ([self type] == SPSocketConnection) {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection lastErrorMessage]];
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil];
- }
- else {
- errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %ld seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], (long)[[prefs objectForKey:SPConnectionTimeoutValue] integerValue], [mySQLConnection lastErrorMessage]];
- [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil];
+ if (!cancellingConnection) {
+ NSString *errorMessage = @"";
+ if (sshTunnel && [sshTunnel state] == SPMySQLProxyForwardingFailed) {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because the port connection via SSH was refused.\n\nPlease ensure that your MySQL host is set up to allow TCP/IP connections (no --skip-networking) and is configured to allow connections from the host you are tunnelling via.\n\nYou may also want to check the port is correct and that you have the necessary privileges.\n\nChecking the error detail will show the SSH debug log which may provide more details.\n\nMySQL said: %@", @"message of panel when SSH port forwarding failed"), [self host], [mySQLConnection lastErrorMessage]];
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"SSH port forwarding failed", @"title when ssh tunnel port forwarding failed") errorMessage:errorMessage detail:[sshTunnel debugMessages]];
+ }
+ else if ([mySQLConnection lastErrorID] == 1045) { // "Access denied" error
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@ because access was denied.\n\nDouble-check your username and password and ensure that access from your current location is permitted.\n\nMySQL said: %@", @"message of panel when connection to host failed due to access denied error"), [self host], [mySQLConnection lastErrorMessage]];
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Access denied!", @"connection failed due to access denied title") errorMessage:errorMessage detail:nil];
+ }
+ else if ([self type] == SPSocketConnection && (![self socket] || ![[self socket] length]) && ![mySQLConnection socketPath]) {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"The socket file could not be found in any common location. Please supply the correct socket location.\n\nMySQL said: %@", @"message of panel when connection to socket failed because optional socket could not be found"), [mySQLConnection lastErrorMessage]];
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket not found!", @"socket not found title") errorMessage:errorMessage detail:nil];
+ }
+ else if ([self type] == SPSocketConnection) {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect via the socket, or the request timed out.\n\nDouble-check that the socket path is correct and that you have the necessary privileges, and that the server is running.\n\nMySQL said: %@", @"message of panel when connection to host failed"), [mySQLConnection lastErrorMessage]];
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Socket connection failed!", @"socket connection failed title") errorMessage:errorMessage detail:nil];
+ }
+ else {
+ errorMessage = [NSString stringWithFormat:NSLocalizedString(@"Unable to connect to host %@, or the request timed out.\n\nBe sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently %ld seconds).\n\nMySQL said: %@", @"message of panel when connection to host failed"), [self host], (long)[[prefs objectForKey:SPConnectionTimeoutValue] integerValue], [mySQLConnection lastErrorMessage]];
+ [[self onMainThread] failConnectionWithTitle:NSLocalizedString(@"Connection failed!", @"connection failed title") errorMessage:errorMessage detail:nil];
+ }
}
// Tidy up
@@ -177,7 +179,7 @@ static NSString *SPLocalhostAddress = @"127.0.0.1";
if (sshTunnel) [sshTunnel release], sshTunnel = nil;
[mySQLConnection release], mySQLConnection = nil;
- [self _restoreConnectionInterface];
+ if (!cancellingConnection) [self _restoreConnectionInterface];
[pool release];
return;
@@ -339,14 +341,13 @@ static NSString *SPLocalhostAddress = @"127.0.0.1";
/*
* Cancel connection.
- * Currently only cleans up the SSH connection (MySQL connection isn't threaded)
*/
- (void)cancelConnection
-{
- if (!sshTunnel) return;
-
+{
cancellingConnection = YES;
-
+
+ if (!sshTunnel) return;
+
[sshTunnel disconnect];
[sshTunnel release];