Copy link to clipboard
Copied
Ok, so I've got a strange problem that I've been beating my head against for over a week now. I'm holding out a little hope that maybe someone here has seen something like this and has a solution or at least can point me in a direction to make some sense of it.
We are running an enterprise application on CF9 currently. Recently we made a large update with some advancements and in part of the advancements I'm using some request scoped variables.
Said request variable is a structure that is set in Application.cfc OnRequestStart. Randomly since the changes have been put on our production servers we get an error email (we have an error handler defined to capture and email errors when they occur), stating that key.subkey is undefined in request scoped variable. What makes this so bizarre is in the email from the error handler (that is processed in the same request) shows the key.subkey existing in the request scoped variable in a <cfdump var="#request#"> in the email. How could it possibly be erroring on a part of the page that runs after OnRequestStart, but before OnError, saying that this structure element doesn't exist yet it does exist during the error handler caused by it. The request scoped variable btw is not defined or set anywhere else outside of the Application.cfc.
I should also mention that other keys in the structure are referenced in the request prior to the point of failure without erroring, some in the same function as the point of error even. It's almost as if the structure is not fully defined yet while it's processing the page request, but it is fully defined by the time it dumps it in the error email....
This problem is really baffling me, and it makes it worse that I can't find any way to reproduce it on our testing servers.
Copy link to clipboard
Copied
It is more likely that a second request is involved. It attempts to access the last element in the structure while the first request is still writing to the structure. If so, then a solution would be to put a lock, of exclusive type, around the first code.
Copy link to clipboard
Copied
BKBK wrote:
a solution would be to put a lock, of exclusive type, around the first code.
That's what I recommended earlier in this thread, but Steven seems averse to locking code even though it ensures data integrity. Locking really does have a valid purpose.
Cheers
Eddie
Copy link to clipboard
Copied
So you did. As they say, EddieLotter, when you're right you're right.
Copy link to clipboard
Copied
BKBK wrote:
As they say...
Who's been talking behind my back??
Cheers
Eddie
Copy link to clipboard
Copied
EddieLotter wrote:
BKBK wrote:
a solution would be to put a lock, of exclusive type, around the first code.
That's what I recommended earlier in this thread, but Steven seems averse to locking code even though it ensures data integrity. Locking really does have a valid purpose.
Cheers
Eddie
Actually, you might want to check the definition of adverse because I said I would add the cflock to see if it made a difference.
Further, in the test case I described above that I was able to reproduce the error in, there was an exclusive lock around the write and a readonly lock around where the error occurred. So the locks apparently didn't help.
I'm also 100% positive in the test case there was a single request.
Copy link to clipboard
Copied
I do believe we're missing something. What does Coldfusion say in the dump of arguments.exception ? What is the error message literally? Even better, could you share the stack trace with us, together with the offending code block?
Copy link to clipboard
Copied
Steven6282 wrote:
Actually, you might want to check the definition of adverse because I said I would add the cflock to see if it made a difference.
I said you were averse to doing it, not that you wouldn't do it, based on your response to my mentioning it. Take a deep breath, we're trying to help you here.
Steven6282 wrote:
Further, in the test case I described above that I was able to reproduce the error in, there was an exclusive lock around the write and a readonly lock around where the error occurred. So the locks apparently didn't help.
If you have managed to create a test case that can reproduce the problem, then post that code so that others can test it in their environments and report back with their findings.
Cheers
Eddie
Copy link to clipboard
Copied
Steven6282 wrote:
What makes this so bizarre is in the email from the error handler (that is processed in the same request) shows the key.subkey existing in the request scoped variable in a <cfdump var="#request#"> in the email. How could it possibly be erroring on a part of the page that runs after OnRequestStart, but before OnError, saying that this structure element doesn't exist yet it does exist during the error handler caused by it.
Your application might inadvertently be triggering an additional request. Although the variable is read in onRequestStart the error occurs where Coldfusion writes the variable.
To get information about where that happens, replace the dump of the request scope (in onError) with:
<cfdump var="#arguments.exception#">