Search code examples
structcoldfusioncoldfusion-11

ColdFusion variables missing


OK, I've been working with ColdFusion for 20 years and have never seen this. I have a ContentBox site (don't believe that is influencing the issue, but wanted to include the info) where I have front end web pages being pulled and back end code being run via event gateway. I receive around 30 gateway events every minute. My problem is that I have variables disappearing mid-routine when the front end web pages are run (typically to pull data from a database).

Because ContenBox/ColdBox module directories have Application.cfcs containing abort commands, the gateway event cfc is in a subfolder directly under the application root (since any aborts in a gateway cfc, or its Application.cfc, results in a gateway error).

The error point in the code is ever changing. Sometimes it's a structure key not being present WHILE looping over a structure's keys:

for(var structKey in structureName)
{
    var structValue = structureName[structKey];
}

Other times the code is referencing a structure in the application scope and, again, a key that is present a few lines earlier is now missing and throwing an error. So it seems the various variable scopes (variables, application, etc.) are losing their values while the web page is being processed (which is often happening while gateway events are being processed).

The web server is tightly secured, and I don't have the issue in dev/staging which is not secured. So my instinct, of course, is that something in the security is causing this issue. I haven't seen anything in logs that can point me to the issue.

Due to contractual obligations, I cannot post the code here. That said, I think the description lends itself to the idea that the issue isn't with the CF code, but the hardening of the server.

Does anyone have any ideas what kinds of things could cause a CF application to lose variables mid-stream?


Solution

  • Problem solved. While a race condition sounded reasonable, I didn't see how it could be happening within such a concise loop in a single thread. But it was, indeed, a race condition. The problem arose from the fact that the code is in a ColdBox handler. I had misunderstood the usage of Wirebox in this instance. I thought that calling the handler would be creating an individual instance of the cached singleton of the handler. Instead, all calls are using the same instance! This means that each call of the handler shares the variables scope with the other concurrent calls, not just itself. That is how the variables were being overwritten.

    Twenty years of ColdFusion, but first project with ColdBox and ContentBox. C'est la vie.