0

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?

J G
  • 19
  • 5
  • 2
    Could be a race condition. Are you scoping your variables? See http://stackoverflow.com/q/19859690/1636917, and http://stackoverflow.com/q/36942015/1636917, and http://stackoverflow.com/q/27408067/1636917 for some discussion on it. – Miguel-F Aug 30 '16 at 11:54
  • *Could be a race condition* ... especially given the sporadic nature of the errors, which is a classic symptom of race conditions. Typically, they only manifest under load. – Leigh Aug 30 '16 at 21:15
  • I'm pretty sure it's not a race condition. I changed the code to put the socket gateway events in a separate application and now my only issue is with referencing existing variables that aren't in the application scope. Often, as I noted above, when looping over a structure's keys. When I create the loop, I always use var (though my original code bit in the post doesn't... I'm editing that). I'm specifically calling the variables by scope (e.g. variables.this["that"], etc.). – J G Aug 31 '16 at 13:53
  • As an added note, sometimes the error thrown is a Java error: java.util.ConcurrentModificationException. As a Java developer at my office explained, that typically results from keys being removed while you are looping over the keys. That said, it doesn't happen every time, and I am not doing anything to remove/delete/change any keys, only subValues (the values of the keys being iterated are themselves structures). – J G Aug 31 '16 at 14:46
  • Well in a way ConcurrentModificationException *is* a race condition ;-) Granted, there are other causes than just lack of var scoping. *(the values of the keys being iterated are themselves structures).* A) Hm...what does the code do with the substructures? B) Are the structures "function local" or function arguments? Because structures are passed by reference. While I can appreciate the "proprietary" issue, it is hard to speculate without much code or error messages. Any chance you could dummy up a small, generic example ie "apples/oranges/pears" and a "scrubbed" stack trace? ;-) – Leigh Sep 01 '16 at 20:47

1 Answers1

1

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.

J G
  • 19
  • 5