I've got two replicated databases that I'm doing app-side failover for
in my CFMX app. The gist of my problem is: I've got some catch blocks
which send failure notices to the DB admins. However, when I'm testing
(stopping the DBs), for a single page request in which there is a
caught error, there is some strange loop developing, and sending
endless emails until I kill the cf service.
I've included the code that I think is pertinent, and have snipped out
the rest (...).
BTW, the line:
<cfthrow message="This error is thrown when both DBs fail.">
Is the one currently that's generating the repeated emails (via
<cferror type="exception">)
Any hints would be greatly appreciated, as I saw the problem when I
posted to production, which was at @ 7PM, and I'm still here trying to
solve it at 5:30AM.
Thanks,
Jamie
[Application.cfm]
<cfscript>
if (cgi.server_name contains "dev") {
thisServer = "dev";
thisApplicationName = "afca_2003_dev";
//thisApplicationDSN = "AF-DB1";
} else if (cgi.server_name contains "stage") {
thisServer = "stage";
thisApplicationName = "afca_2003_stage";
//thisApplicationDSN = "AF-DB2";
} else {
thisServer = "prod";
thisApplicationName = "afca_2003";
}
request.thisServerName = #cgi.server_name#;
request.dbtype = 'odbc';
</cfscript>
<cfinclude template="_functions.cfm">
<!--- this conditional spans the rest of the application.cfm and sets
a variable
"skipAppAndORE" which controls the same behavior in
OnRequestEnd.cfm --->
<cfif cgi.script_name contains 'styles'>
<cfset skipAppAndORE = true>
<cfelse>
<cfset skipAppAndORE = false>
<!--- ############ DATASOURCE-DETERMINATION CODE
###############################
create an array (DSNAry) of potential data sources
###########################################################################
--->
<cfscript>
request.DSNAry = arrayNew(1);
request.DSNAry[1] = "AF-DB1";
request.DSNAry[2] = "AF-DB2";
</cfscript>
<cfscript>
/* initialize some vars */
// do we loop over the array again? yes, by default for first loop
appIterateAgain = true;
// how many array elements?
appDSNAryLength = arrayLen(request.DSNAry);
// initialize loop count to 1
appIndex = 1;
// initialize successful db connection var
dbConnectSuccess = true;
dbSwitched = false;
</cfscript>
<cfloop condition="appIterateAgain AND appIndex LTE 2">
<cfscript>
// don't reiterate over the loop if this stays false
appIterateAgain = false;
// for use after the loop
appDSNAryIndex = appIndex;
// get the dsn from the array
appDSN = request.DSNAry[appIndex];
</cfscript>
<cftry>
<cfquery name="dbCheck" datasource="#appDSN#"
dbtype="#request.dbtype#">
SELECT "HI" AS Lois
</cfquery>
<cfcatch>
<cfif appIndex IS arrayLen(request.DSNAry)>
<!--- end of the line, give up --->
<cfset dbConnectSuccess = false>
<cfelse>
<!--- there are more attempts to be made, keep looping --->
<cfset appIterateAgain = true>
<cfset dbSwitched = true>
</cfif>
</cfcatch>
</cftry>
<!--- increment this loop's index --->
<cfset appIndex = appIndex + 1>
</cfloop>
<cfif dbConnectSuccess>
<cfif dbSwitched>
<!--- DB1 DIED, AND DB2 HANDLED IT --->
<cfapplication name="#thisApplicationName#" setClientCookies="No"
clientmanagement="Yes" clientstorage="#appDSN#">
<cferror type="EXCEPTION" template="_error.cfm"
mailto="[EMAIL PROTECTED]">
<cferror type="REQUEST" template="_RequestError.cfm">
<cflog text="The DB switched from '#request.dsnAry[1]#' to
'#request.DSNAry[appDSNAryIndex]#.'" type="Information"
file="AFCASurvey2003CustomLog" thread="yes" date="yes" time="yes"
application="yes">
<cfif timeToSendEmail("dbSwitched", 30)>
<cfmail ...>
...
</cfmail>
</cfif>
</cfif>
<cfelse>
<!--- PRIMARY AND FAILOVER DB DEAD, set simplified <cfapplication>,
etc. --->
<cfapplication name="#thisApplicationName#" setclientcookies="No">
<cferror type="EXCEPTION" template="_error.cfm"
mailto="[EMAIL PROTECTED]">
<cferror type="REQUEST" template="_RequestError.cfm">
<cflog text="Both DB connections failed." type="Error"
file="AFCASurvey2003CustomLog" thread="yes" date="yes" time="yes"
application="yes">
<cfif timeToSendEmail("dbsFailed", 30)>
<cfmail ...>
...
</cfmail>
</cfif>
<cfthrow message="This error is thrown when both DBs fail.">
</cfif>
<!--- set the dsn to be used throughout the application --->
<cfset request.dsn = appDSN>
<!--- ############ END DATASOURCE-DETERMINATION CODE
###################### --->
<!--- ############ TIMEOUT CLIENT VARIABLES
############################### --->
<CF_ClientTimeout TimeOut = 45>
</cfif>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription:
http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Signup for the Fusion Authority news alert and keep up with the latest news in
ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm
Unsubscribe:
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4