In my last post on object factories, I talked about how my attempt to use an object factory for Galleon had led to infinite loop. More than one person told me to switch to ColdSpring and rethink my CFC setup in general (which I agree with), but at the same time I was curious as to why the factory didn't work when I expected it to. Rob Gonda (who had provided the original code) was able to figure out the issue.

Let me quickly go over again the process I was using. This is a simplified version of what Galleon is doing and it will lead to demonstrating the bug.

First off - the factory's general methodology is to make a CFC and return it to you. However, it is smart enough to create singletons. By that I mean the factory would cache the CFC in the variables so on the 2nd-N calls it would return the cached version.

So when Galleon was starting up, it did this:

  1. Ask for Message.cfc.
  2. Factory would make a new instance and begin to set things inside it.
  3. One of those things was the Thread CFC.
  4. Thread CFC needs a copy of Message.cfc. It would ask the factory and a new one was made since back in step 1 the process never got finished.
  5. Loop until CPU goes ape-you-know-what.

So the important thing to note is that because the first process (Ask for Message.cfc) never finished, when Thread asked for a new copy, it didn't load from the cache. That was the problem.

If you take the above process and change it a bit...

  1. Ask for Message.cfc.
  2. Factory would make a new instance and place in cache
  3. Begin to set things inside it.
  4. One of those things was the Thread CFC.
  5. Thread CFC needs a copy of Message.cfc. It would ask the factory and the cached one is returned.

Like most bugs - now that I see it (thanks again Rob), it is so obvious I can't believe I missed it. I still need to rework Galleon's CFCs, but I can at least get the new release out. (Look for it tonight.)