On a somewhat consistent basis I'll get an error l...
# cfml-general
b
On a somewhat consistent basis I'll get an error like, "Element MyVariable is undefined in APPLICATION." When I look in the application.cfc the variable is defined in the onApplicationStart method. Not only that, but if I restart the application the error goes away. It's like it randomly losing state or something. How can it be running without having run onApplicationStart? Any ideas on how to diagnose this would be appreciated. It's the irregular errors that are buggers to figure out.
e
1. Is it always the same variable that is undefined? 2. Is it always throwing the undefined error at the same spot in the code? 3. Are there other variables defined in onStart? I would probably start with adding some logging to correlate/prove that onStart did run (or did not, but seems unlikely) on the same request when the error is hit. That would prove either that onStart ran (which must mean the var is being lost somewhere else) or it didn't run and can focus on that issue. In onStart i would add a log entry of some kind: file/database - whatever is convenient, heck could even clone your application scope into a new request scope var, then when error is encountered check the log - if its the same line of code this is easy, just check for undefined or catch it and then write to the same logging, or check that request clone of application scope to see if the var is defined there.
b
I will certainly add logging as the errors occur. To answer your questions: 1. No, it's not always the same variable. It's not even always the same app. 2. Due to item 1, no, it's not always the same spot in the code. 3. Yes, there are a bunch of other variables defined in that method. If nothing else, you've made me realize my data tracking has been insufficient. I'll do much better going forward and see if I can find any patterns. Thanks!
e
good luck! It would be interesting then to globally catch the error and dump the entire application scope somewhere - that would at least tell you which vars are missing which might give a clue
b
There is no way to record an entire scope in a log like that, is there?
e
sure, simplest is just serialize it to JSON and write that out
or if you have a very convoluted application scope, and only need top level plain vars, just do a simple loop over the application keys and write out the key:value pairs
👍 1
j
What is your application timeout set to? I have seen this occur on Lucee and ColdFusion when the application timeout hits while another request is processing.
👍🏼 1
In production, we set our application timeouts to a year to prevent this
e
except possibly once a year? 🙂
m
I would check out application names and make sure it is unique and not being reused... if the application name is reused then the application life cycle and everything else can be hokey.... Even check for wrongful or incomplete inheritance...
j
> except possibly once a year? Well, we deploy everything these days in Docker so it’s pretty rare to have a single container running for a year. 🙂 We’ll have to cross that bridge when we come to it…
👍 1
m
Jon's suggestion is a good one. Also please check that you're naming all of your applications. Unnamed Applications share application scope variables and collisions and other sundry nonsense can occur. One of the first things I always do on a server install is check the "disable creation of unnamed applications" to avoid that particular silly issue (other silly issues still occur).
b
Thanks for all of the suggestions! All of the application timeouts were set to two days, so these have been changed and hopefully that will fix the issue. 🙂
b
Copy code
@Brian: There is no way to record an entire scope in a log like that, is there?
You can use the following single line of code to dump the application scope as an HTML file within the default logs directory:
<!---<cfdump var="#application#" label="Application Scope" format="html" output="#server.coldfusion.rootDir#\logs\ApplicationScopeDump.html">--->
<cfscript>
writedump(var="#application#", label="Application Scope", format="html", output="#server.coldfusion.rootDir#\logs\ApplicationScopeDump.html");
</cfscript>
ColdFusion will format the dump in such a way that you can conveniently view it in the browser.
👍 1
Copy code
@Brian: On a somewhat consistent basis I'll get an error like, "Element MyVariable is undefined in APPLICATION." When I look in the application.cfc the variable is defined in the onApplicationStart method. Not only that, but if I restart the application the error goes away. It's like it randomly losing state or something. How can it be running without having run onApplicationStart?
My first guess is: • either the application variable is being deleted (structdelete) or set to null, or • the entire application scope is being deleted (structclear) in a CFM page, in a function or in a CFC method somewhere.
To explore where any unintentional deletes might be happening, search the code base for occurrences of the word "application".
s
@jclausen I get an apparent app timeout on one project even though I set the app timeout to about a week. I've been under the impression that if nobody hits the app it will timeout but my client tells me that people are using it.
Occasionally I will get it if the server itself is restarted as well. Coldfusion will come up as expected but the app will stick until I force an onapplicationstart
@BK BK that search won't help if the problem is in the application file itself v
m
Where are you setting the app timeout and are you sure it isn't being set elsewhere?
s
*.
@Mark Takata (Adobe) was that at me or the op?
Whether aimed at me or not though my timeout is set in the pseudo constructor of application.cfc or whatever you term the section where orm etc is configured
The same place I set the session timeout I think
I'm also a bit confused about how important the app timeout is compared to the session timeout. Does the session impact the application?
b
Copy code
@salted :@BK BK that search won't help if the problem is in the application file itself
You perhaps didn't understand what I meant. The search for application-scoped variables is in fact a search for a possible cause of the issue in the application itself. As I had said earlier, you would then be looking for places where application variables are deleted, even if unintentionally.
s
Ah got ya