I have a client website that does not get a lot of traffic right now. They might get a handful of visitors in a week, so there may be periods of time where there are no website visitors for more than 24 hours. I have noticed that after trying to load this website after it has not received any traffic for a few days, I am often will be greeted with a Coldbox error like this:
The error goes away after a simple fwreinit command, but I’d like to make sure that the first visitor that accesses the site doesn’t encounter this problem.
Are there any strategies I could use to ensure that Coldbox is properly warmed up and initialized at all times, or perhaps a way to have a request check if the framework was properly initialized, and if not, automatically reinit?
When messages like this appear, it’s usually because the application has timed out and Coldbox still thinks it’s ready to go.
First of all, I would suggest checking your Application.cfc to make sure it’s using the Coldbox 5.x Bootstrap logic.
Effectively, your onRequestStart should be re-running the Bootstrap if the expected cbController and wirebox keys are not in the application scope. This bootstrap should happen when the app scope is restarted, of course, as well.
If those are being checked, then there may be something with the application timeout/restart that is causing keys to be retained that should be wiped. The wirebox namespace mappings are placed in a nested object within the application scope.
// request start
public boolean function onRequestStart(String targetPage){
// Process ColdBox Request
application.cbBootstrap.onRequestStart( arguments.targetPage );
return true;
}
It doesn’t look like my code makes any checks in the method, but I could see adding some type of if() statement in there would be a good idea. Do you have an example of a better onRequestStart() which makes the appropriate checks before executing the request?
I notice the docs don’t include the “onApplicationEnd” method.
I also always add a check for the “cbBootstrap” and the “wirebox” keys in the application scope at the top of onRequestStart as a fallback. If either don’t exist, I rerun “onApplicationStart” which ensures a full initialization of the framework.
Bingo. I always put that check at the top of “onRequestStart” as a “catch all” failsafe.
Luis might have a better idea on why the app restart isn’t happening cleanly.
Nowadays I run almost all CFML apps in Docker and there I set an application timeout of 1 year, so the application never times out and recreates. As such I’ve only seen errors like yours in development.