aboutsummaryrefslogtreecommitdiffstats
path: root/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m
diff options
context:
space:
mode:
Diffstat (limited to 'Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m')
-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];