aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m6
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h3
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m3
-rw-r--r--Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m13
-rw-r--r--Source/SPDatabaseStructure.m12
5 files changed, 35 insertions, 2 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
index f001d332..e5a48d48 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Querying & Preparation.m
@@ -58,6 +58,9 @@
* Take a string and escapes any special character for safe use within a query; correctly
* escapes any characters within the string using the current connection encoding.
* Allows control over whether to also wrap the string in single quotes.
+ *
+ * WARNING: This method may return nil if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (NSString *)escapeString:(NSString *)theString includingQuotes:(BOOL)includeQuotes
{
@@ -222,6 +225,9 @@
* the connection encoding.
* The result type desired can be specified, supporting either standard or streaming
* result sets.
+ *
+ * WARNING: This method may return nil if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (id)queryString:(NSString *)theQueryString usingEncoding:(NSStringEncoding)theEncoding withResultType:(SPMySQLResultType)theReturnType
{
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h
index 844a6b5f..8ec6c9e0 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.h
@@ -49,6 +49,9 @@
* mysql_shutdown() - If the user has the permission, will shutdown the (remote) server
* @return Whether the command was executed successfully
* Note: this can also be NO if the user denied a reconnect attempt.
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)serverShutdown;
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
index f9949121..db846929 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection Categories/Server Info.m
@@ -98,6 +98,9 @@
* the resulting process list defaults to the short form; run a manual SHOW FULL PROCESSLIST
* to retrieve tasks in non-truncated form.
* Returns nil on error.
+ *
+ * WARNING: This method may return nil if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (SPMySQLResult *)listProcesses
{
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
index 365f8649..b09a27ee 100644
--- a/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
+++ b/Frameworks/SPMySQLFramework/Source/SPMySQLConnection.m
@@ -282,6 +282,9 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
* Error checks extensively - if this method fails, it will ask how to proceed and loop depending
* on the status, not returning control until either a connection has been established or
* the connection and document have been closed.
+ *
+ * WARNING: This method may exit early returning NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)reconnect
{
@@ -330,10 +333,12 @@ const char *SPMySQLSSLPermissibleCiphers = "DHE-RSA-AES256-SHA:AES256-SHA:DHE-RS
* Checks whether the connection to the server is still active. This verifies
* the connection using a ping, and if the connection is found to be down attempts
* to quickly restore it, including the previous state.
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)checkConnection
{
-
// If the connection is not seen as active, don't proceed
if (state != SPMySQLConnected) return NO;
@@ -647,6 +652,9 @@ static uint64_t _elapsedMicroSecondsSinceAbsoluteTime(uint64_t comparisonTime)
* the connection and document have been closed.
* Runs its own autorelease pool as sometimes called in a thread following proxy changes
* (where the return code doesn't matter).
+ *
+ * WARNING: This method may exit early returning NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)_reconnectAllowingRetries:(BOOL)canRetry
{
@@ -1019,6 +1027,9 @@ static uint64_t _elapsedMicroSecondsSinceAbsoluteTime(uint64_t comparisonTime)
* each of which requires a round trip to the server - but handles most
* network issues.
* Returns whether the connection is considered still valid.
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)_checkConnectionIfNecessary
{
diff --git a/Source/SPDatabaseStructure.m b/Source/SPDatabaseStructure.m
index e11959b1..a4663268 100644
--- a/Source/SPDatabaseStructure.m
+++ b/Source/SPDatabaseStructure.m
@@ -288,6 +288,7 @@
if(![aTableName isKindOfClass:[NSString class]] || ![aTableName length]) continue;
// check the connection.
+ // also NO if thread is cancelled which is fine, too (same consequence).
if(![self _checkConnection]) {
goto cleanup_thread_and_pool;
}
@@ -345,6 +346,7 @@
// If the MySQL version is higher than 5, also retrieve function/procedure details via the information_schema table
if ([mySQLConnection serverMajorVersion] >= 5) {
// check the connection.
+ // also NO if thread is cancelled which is fine, too (same consequence).
if(![self _checkConnection]) {
goto cleanup_thread_and_pool;
}
@@ -536,6 +538,9 @@ cleanup_thread_and_pool:
*
* **Unsafe** means this function holds no lock on connectionCheckLock.
* You MUST obtain that lock before calling this method!
+ *
+ * WARNING: This method may return NO if the current thread is cancelled!
+ * You MUST check the isCancelled flag before using the result!
*/
- (BOOL)_ensureConnectionUnsafe
{
@@ -543,6 +548,9 @@ cleanup_thread_and_pool:
// Check the connection state
if ([mySQLConnection isConnected] && [mySQLConnection checkConnection]) return YES;
+
+ // the result of checkConnection may be meaningless if the thread was cancelled during execution. (issue #2353)
+ if([[NSThread currentThread] isCancelled]) return NO;
// The connection isn't connected. Check the parent connection state, and if that
// also isn't connected, return.
@@ -630,6 +638,8 @@ cleanup_thread_and_pool:
/**
* @return YES if the connection is available
* NO if either the connection failed, or this thread was cancelled
+ *
+ * You MUST check the thread's isCancelled flag before doing other stuff on negative return!
*/
- (BOOL)_checkConnection
{
@@ -659,7 +669,7 @@ cleanup_thread_and_pool:
if (!cancelThread) {
// Check connection state before use
- connected = [self _ensureConnectionUnsafe];
+ connected = [self _ensureConnectionUnsafe]; // also does a thread canellation check
}
pthread_mutex_unlock(&connectionCheckLock);