aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSSHTunnel.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-10-30 22:30:47 +0000
committerrowanbeentje <rowan@beent.je>2012-10-30 22:30:47 +0000
commitbd51b74145153281edddbc6f2f5d165b3249dc41 (patch)
tree17d14774a4ad0d24e0218c62048b812b17316ad7 /Source/SPSSHTunnel.m
parente3d3ff956b73e2713b36e292744956c1e0e9b805 (diff)
downloadsequelpro-bd51b74145153281edddbc6f2f5d165b3249dc41.tar.gz
sequelpro-bd51b74145153281edddbc6f2f5d165b3249dc41.tar.bz2
sequelpro-bd51b74145153281edddbc6f2f5d165b3249dc41.zip
- If the connection exits unexpectedly when muxing, disable connection muxing and retry; this should address Issue #1457
- Add SSH command and task arguments used to the debug log
Diffstat (limited to 'Source/SPSSHTunnel.m')
-rw-r--r--Source/SPSSHTunnel.m39
1 files changed, 29 insertions, 10 deletions
diff --git a/Source/SPSSHTunnel.m b/Source/SPSSHTunnel.m
index 467c43fc..60a8cf84 100644
--- a/Source/SPSSHTunnel.m
+++ b/Source/SPSSHTunnel.m
@@ -44,6 +44,8 @@
@implementation SPSSHTunnel
@synthesize passwordPromptCancelled;
+@synthesize connectionMuxingEnabled;
+@synthesize taskExitedUnexpectedly;
/*
* Initialise with the supplied connection details. Host, login and port should all be provided.
@@ -67,6 +69,7 @@
delegate = nil;
stateChangeSelector = nil;
lastError = nil;
+ connectionMuxingEnabled = YES;
debugMessages = [[NSMutableArray alloc] init];
debugMessagesLock = [[NSLock alloc] init];
answerAvailableLock = [[NSLock alloc] init];
@@ -216,9 +219,12 @@
localPort = 0;
if (connectionState != SPMySQLProxyIdle) return;
+
[debugMessagesLock lock];
[debugMessages removeAllObjects];
[debugMessagesLock unlock];
+ taskExitedUnexpectedly = NO;
+
[NSThread detachNewThreadWithName:@"SPSSHTunnel SSH binary communication task" target:self selector:@selector(launchTask:) object:nil];
}
@@ -309,19 +315,26 @@
// Enable verbose mode for message parsing
[taskArguments addObject:@"-v"];
- // Ensure that the muxed connection can be used for only tunnels, not interactive
+ // Ensure that the connection can be used for only tunnels, not interactive
[taskArguments addObject:@"-N"];
- // Enable automatic connection muxing/sharing, for faster connections
- [taskArguments addObject:@"-o ControlMaster=auto"];
+ if (connectionMuxingEnabled) {
- // Set a custom control path to isolate connection sharing to Sequel Pro, to prevent picking up
- // existing masters without forwarding enabled and to isolate from interactive sessions. Use a short
- // hashed path to aid length limit issues.
- unsigned char hashedPathResult[16];
- NSString *pathString = [NSString stringWithFormat:@"%@@%@:%ld", sshLogin?sshLogin:@"", sshHost, sshPort?sshPort:0];
- CC_MD5([pathString UTF8String], (unsigned int)strlen([pathString UTF8String]), hashedPathResult);
- [taskArguments addObject:[NSString stringWithFormat:@"-o ControlPath=%@/SPSSH-%@", [NSFileManager temporaryDirectory], [[[NSData dataWithBytes:hashedPathResult length:16] dataToHexString] substringToIndex:8]]];
+ // Enable automatic connection muxing/sharing, for faster connections
+ [taskArguments addObject:@"-o ControlMaster=auto"];
+
+ // Set a custom control path to isolate connection sharing to Sequel Pro, to prevent picking up
+ // existing masters without forwarding enabled and to isolate from interactive sessions. Use a short
+ // hashed path to aid length limit issues.
+ unsigned char hashedPathResult[16];
+ NSString *pathString = [NSString stringWithFormat:@"%@@%@:%ld", sshLogin?sshLogin:@"", sshHost, sshPort?sshPort:0];
+ CC_MD5([pathString UTF8String], (unsigned int)strlen([pathString UTF8String]), hashedPathResult);
+ [taskArguments addObject:[NSString stringWithFormat:@"-o ControlPath=%@/SPSSH-%@", [NSFileManager temporaryDirectory], [[[NSData dataWithBytes:hashedPathResult length:16] dataToHexString] substringToIndex:8]]];
+ } else {
+
+ // Disable muxing if requested
+ [taskArguments addObject:@"-o ControlMaster=no"];
+ }
// If the port forwarding fails, exit - as this is the primary use case for the instance
[taskArguments addObject:@"-o ExitOnForwardFailure=yes"];
@@ -381,6 +394,11 @@
}
[task setEnvironment:taskEnvironment];
+ // Add the connection details to the debug messages
+ [debugMessagesLock lock];
+ [debugMessages addObject:[NSString stringWithFormat:@"Used command: %@ %@\n", [task launchPath], [[task arguments] componentsJoinedByString:@" "]]];
+ [debugMessagesLock unlock];
+
// Set up the standard error pipe
standardError = [[NSPipe alloc] init];
[task setStandardError:standardError];
@@ -406,6 +424,7 @@
// If the task closed unexpectedly, alert appropriately
if (connectionState != SPMySQLProxyIdle) {
connectionState = SPMySQLProxyIdle;
+ taskExitedUnexpectedly = YES;
if (lastError) [lastError release];
lastError = [[NSString alloc] initWithString:NSLocalizedString(@"The SSH Tunnel has unexpectedly closed.", @"SSH tunnel unexpectedly closed")];
if (delegate) [delegate performSelectorOnMainThread:stateChangeSelector withObject:self waitUntilDone:NO];