@@ -199,6 +199,8 @@ - (id)init
// while running them
retryQueriesOnConnectionFailure = YES ;
_debugLastConnectedEvent = nil ;
// Start the ping keepalive timer
keepAliveTimer = [[SPMySQLKeepAliveTimer alloc ] initWithInterval: 10 target: self selector: @selector (_keepAlive )];
@@ -253,6 +255,8 @@ - (void) dealloc
if (querySqlstate) [querySqlstate release ], querySqlstate = nil ;
[delegateDecisionLock release ];
[_debugLastConnectedEvent release ];
[NSObject cancelPreviousPerformRequestsWithTarget: self ];
[super dealloc ];
@@ -428,6 +432,14 @@ + (NSString *)findSocketPath
const char *__crashreporter_info__ = NULL ;
asm (" .desc ___crashreporter_info__, 0x10" );
static uint64_t _elapsedMicroSecondsSinceAbsoluteTime (uint64_t comparisonTime)
{
uint64_t elapsedTime_t = mach_absolute_time () - comparisonTime;
Nanoseconds elapsedTime = AbsoluteToNanoseconds (*(AbsoluteTime *)&(elapsedTime_t));
return (UnsignedWideToUInt64 (elapsedTime) / 1000ULL );
}
@implementation SPMySQLConnection (PrivateAPI)
/* *
@@ -438,8 +450,11 @@ - (BOOL)_connect
// If a connection is already active in some form, throw an exception
if (state != SPMySQLDisconnected && state != SPMySQLConnectionLostInBackground) {
asprintf (&__crashreporter_info__, " Attempted to connect a connection that is not disconnected (SPMySQLConnectionState=%d )." , state);
__builtin_trap ();
@synchronized (self) {
uint64_t diff = _elapsedMicroSecondsSinceAbsoluteTime (initialConnectTime);
asprintf (&__crashreporter_info__, " Attempted to connect a connection that is not disconnected (SPMySQLConnectionState=%d ).\n If state==2: Previous connection made %llu µs ago from: %s " , state, diff, [_debugLastConnectedEvent cStringUsingEncoding: NSUTF8StringEncoding]);
__builtin_trap ();
}
[NSException raise :NSInternalInconsistencyException format: @" Attempted to connect a connection that is not disconnected (SPMySQLConnectionState=%d )." , state];
return NO ;
}
@@ -472,7 +487,13 @@ - (BOOL)_connect
// Successfully connected - record connected state and reset tracking variables
state = SPMySQLConnected;
initialConnectTime = mach_absolute_time ();
@synchronized (self) {
initialConnectTime = mach_absolute_time ();
[_debugLastConnectedEvent release ];
_debugLastConnectedEvent = [[NSString alloc ] initWithFormat: @" thread=%@ stack=%@ " ,[NSThread currentThread ],[NSThread callStackSymbols ]];
}
mysqlConnectionThreadId = mySQLConnection->thread_id ;
lastConnectionUsedTime = initialConnectTime;