Search code examples
coldfusionrequesttimeoutnotifycfquery

Receive email alert when Coldfusion CFQUERY time limit exceeded


This morning our Amazon EC2 Windows server became nearly unresponsive, throwing 500 errors intermittently. In the CF log I see a bunch of these errors:

The request has exceeded the allowable time limit Tag: CFQUERY 

After rebooting the server, everything is back to normal.

While I hunt down the root cause for this, is it possible to configure CF Admin to send an email when a certain Log File error begins to appear several times in a row, like this one? We have already configured Health Status Checks for outages on EC2, but they never triggered because the server was still running, just incredibly slowly. I would like to be the first responder to situations like this but didn't know because I wasn't actively monitoring the server when it occurred - a user had to alert me to the problem a couple of hours later, which is embarrassing for me.

Thanks in advance!


Solution

  • Don't know if this is best practice, but what I do is utilize the OnError function in the application.cfc for reporting of unhandled errors.

    <cffunction name="onError" returnType="void" hint="Runs when an uncaught exception occurs in the application.">
        <cfargument name="Exception" required=true/>
        <cfargument name="EventName" type="String" required=true/>
    
        <cfmail to="[email protected]" from="[email protected]" subject="Error Alert" type="html">
            <cfdump var="#session#">
            <cfdump var="#CGI#">
            <cfdump var="#Exception#">
        </cfmail>
    </cffunction>
    

    You could obviously filter down to the types of errors you want reported.

    If you just want to check specifically in the function (where the time out occurred), then you should use:

    <cffunction name="yourfunction">
        <cftry>
        ...
        <cfcatch>
            <cfmail to="[email protected]" from="[email protected]" subject="Error:yourfunction">
            <cfdump var="#session#">
            <cfdump var="#CGI#">
            <cfdump var="#cfcatch#">
        </cfcatch>
        </cftry>
    <cffunction>