aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-05-30 22:42:19 +0000
committerrowanbeentje <rowan@beent.je>2011-05-30 22:42:19 +0000
commit52c7fd7e1c2155dbb1f2f68d9cf3464398ec2710 (patch)
tree13a23f9d8c115783e992aa5fd3e2f0fedf92b4da /Frameworks/MCPKit/MCPFoundationKit
parent8d7f66b1d81feb622c7ddd9fe6ba495e10e74d24 (diff)
downloadsequelpro-52c7fd7e1c2155dbb1f2f68d9cf3464398ec2710.tar.gz
sequelpro-52c7fd7e1c2155dbb1f2f68d9cf3464398ec2710.tar.bz2
sequelpro-52c7fd7e1c2155dbb1f2f68d9cf3464398ec2710.zip
- After reviewing crash logs, improve query cancellation for increased stability (mostly in the kill query/thread failure path) and improve disconnection for increased stability
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit')
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m17
1 files changed, 14 insertions, 3 deletions
diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
index 7efe4499..0e403eaf 100644
--- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
+++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
@@ -525,7 +525,9 @@ static BOOL sTruncateLongFieldInLogs = YES;
} while (![self tryLockConnection]);
[self unlockConnection];
- if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection);
+ // Only close the connection if it appears to still be active, and not reading or
+ // writing. This may result in a leak, but minimises crashes.
+ if (!mConnection->net.reading_or_writing && mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection);
mConnection = NULL;
}
@@ -580,6 +582,7 @@ static BOOL sTruncateLongFieldInLogs = YES;
// Close the connection if it exists.
if (mConnected) {
+ mConnected = NO;
// Allow any pings or query cleanups to complete - within a time limit.
uint64_t startTime_t, currentTime_t;
@@ -594,11 +597,12 @@ static BOOL sTruncateLongFieldInLogs = YES;
} while (![self tryLockConnection]);
[self unlockConnection];
- if (mConnection->net.vio && mConnection->net.buff) mysql_close(mConnection);
+ // Only close the connection if it's not reading or writing - this may result
+ // in leaks, but minimises crashes.
+ if (!mConnection->net.reading_or_writing) mysql_close(mConnection);
mConnection = NULL;
}
- mConnected = NO;
isDisconnecting = NO;
[self lockConnection];
@@ -2014,6 +2018,13 @@ void pingThreadCleanup(void *pingDetails)
NSLog(@"Task cancelletion MySQL init failed.");
}
+ // As the attempt may have taken up to the connection timeout, check lock status
+ // again, returning if nothing is required.
+ if ([self tryLockConnection]) {
+ [self unlockConnection];
+ return;
+ }
+
// Reset the connection
[self unlockConnection];
if (!isDisconnecting) [self reconnect];