Issues with cflock or not to Lock - coldfusion

i had a cflock when i started getting an error:
has run into a timeout (50 seconds) and has been stopped.
Select all
Open in new window
then i removed the cflock again i am getting the same error
any Idea why
added the cflock with dynamic names and now getting same error with this line added:
Open locks at this time (filereadwrite: 13).
not sure if cflock has anything to do:
because the code is like this:
<cflock name="initre" timeout="10" type="exclusive">
<cfset application.tools = createobject("component","xyz").init()>
</cflock>
and inside the application.tools, i have another function which has a cflock to it but it is a dynamic named lock
inside that cflock, it calls another method which does some processing of returning me struct after inserting into database
i am using the dynamic lock with type: exclusive and timeout: 10

Related

Cache already exists error with CFCACHE

I've recently used CFCACHE to implement page caching on a cold fusion 9 server.
However I'm getting errors reported under load (running an automated link checker) like:
"Cache A95C0BF9E9BFBC6F151F03E939D2D2D6TEMPLATE already exists"
I had thought that cfcache would be thread safe, and handle this without any extra code. If it is relevant I'm calling it within "OnRequest" within my application.cfc. To me it seems like perhaps this is a Cold Fusion bug, but it's also possible I'm abusing the CFCACHE mechanism in some way.
<!--- setup caching if enabled --->
<cfif getConfigValue('page_cache') eq "true" and not application.security.isLoggedOn()>
<cfcache timespan="#createTimeSpan(0,0,10,0)#" directory="#application.pagecachepath#" usequerystring="true" >
</cfif>
<!--- Call request handling and rendering functions --->
<cfcontent reset="yes" type="text/html"><cfoutput>#html.render()#</cfoutput>
<cfif getConfigValue('page_cache') eq "true" and not application.security.isLoggedOn()><!-- content generated at #Now()#--></cfif>
The stack trace is:
net.sf.ehcache.ObjectExistsException: Cache A95C0BF9E9BFBC6F151F03E939D2D2D6TEMPLATE already exists at
net.sf.ehcache.CacheManager.addCacheNoCheck(CacheManager.java:920) at
net.sf.ehcache.CacheManager.addCache(CacheManager.java:915) at
net.sf.ehcache.CacheManager.addCache(CacheManager.java:870) at
coldfusion.tagext.io.cache.ehcache.GenericEhcache.createCache(GenericEhcache.java:317) at
coldfusion.tagext.io.cache.ehcache.GenericEhcache._getCache(GenericEhcache.java:301) at
coldfusion.tagext.io.cache.ehcache.GenericEhcache.getCache(GenericEhcache.java:268) at
coldfusion.tagext.io.cache.ehcache.GenericEhcache.get(GenericEhcache.java:72) at
coldfusion.tagext.io.cache.CacheTagHelper.checkFromTemplateCache(CacheTagHelper.java:56) at
coldfusion.tagext.io.cache.CacheTag.checkTemplatecache(CacheTag.java:695) at
coldfusion.tagext.io.cache.CacheTag.doStartTag(CacheTag.java:609) at
coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722) at cfapplication2ecfc814216694$funcONREQUEST._factor1(C:\inetpub\vhosts\example.org\httpdocs\application.cfc:190) at
cfapplication2ecfc814216694$funcONREQUEST.runFunction(C:\inetpub\vhosts\example.org\httpdocs\application.cfc:187) at
coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472) at
coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405) at
coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368) at
Absent any better ideas I guess I'll start looking into the EH cache source!
race condition in coldfusion.tagext.io.cache.ehcache.GenericEhcache
Looks like it exists in both CF9 & 10 (based on source code)
your only solution is to put cflock somewhere to fix this yourself.

Viewing Execution Stack Trace when there's no access to CFIDE

I'm currently in the process of debugging a ColdFusion system for a client...
Problem is, because they're quite sensitive about any of their systems being screwed up if I were to touch the CF Administrator module, they've made it off limits... And they're quite hesitant to even open it up on a specific IPs because they don't want the stack trace to accidentally be viewed by other users...
So I'm wondering... is there a CF tag or function I can implement in varioous parts of the code to trigger a stack trace in lieu of this access?
If you're trying to get stack traces when errors occur, then you should be able to do that using the onError event on Application.cfc. From there you'll be able to log the exception to a file, send out as an email or hook into something like Hoth or BugLogHG or even 3rd party services like Airbrake or Sentry
// in Application.cfc
function onError(any exception, string event) {
// do something here like send an email / log to file etc
}
If you don't have any errors and you want to get a stack trace then that is harder, but you can fake an error, so something like this might work:
<cfset greeting = "Hello World!">
<cftry>
<!--- deliberately throw an error --->
<cfthrow type="ForceException" message="Thrown Exception">
<cfcatch>
<!---
the cfcatch key has a stacktrace key so you can log/email it
to get the information and the rest of the code will execute
--->
<cflog file="somefile" text="#SerializeJSON(cfcatch)#">
</cfcatch>
</cftry>
<!--- this code will still run --->
<cfoutput>
#greeting#
</cfoutput>

ColdFusion 10 application.cfc error: counting number of active sessions

In the adobe coldfusion 10 documentation, Defining the application and its event handlers in Application.cfc, there is a sample Application.cfc containing the function below. After looking at the code, I am wondering if there is a typo/bug in the following code:
<cffunction name="onSessionStart">
...
<cflock timeout="5" throwontimeout="No" type="EXCLUSIVE" scope="SESSION">
<cfset Application.sessions = Application.sessions + 1>
</cflock>
...
</cffunction>
Should it be:
(A) cflock ... scope="SESSION"
or
(B) cflock ... scope="APPLICATION"
?
If it is (A) then I am confused. Can someone explain why?
This is a duplicate of my answer to the same question asked on the Adobe forums:
Don't be confused... it's an error in the docs. You could do Adobe a
favour by commenting at the bottom of the page: they do monitor those
comments (they don't always react, but the do monitor them).
onSessionStart() is intrinsically single-threaded as far as the
session scope goes: it's only ever run once per session (when the
session starts...). On the other hand the code in question def wants
to single-thread access to that application-scoped variable as we
don't want two simultaneous sessions hitting it for any given single
value of it (if that makes sense).
You always lock the SCOPE that you are writing to. In this case it would be APPLICATION.

coldfusion with memcached client returning error after 270 or so calls

My question seems to be related to this one:
Coldfusion memcached connections
however, i have been unable to solve it.
if i put this code in application.cfm:
<cfif not IsDefined("application.memcached")>
<cfset application.memcachedFactory = createObject("component","memcachedFactory").init("192.168.2.91:11211")>
<cfset application.memcached = application.memcachedFactory.getmemcached()>
</cfif>
the page will work for maybe 270 calls. then it will start to fail with an error "Object Instantiation Exception " The code is properly talking to memcached. I can send and receive data. it seems like java is running out of something .. threads, sockets, handles of some sort. I know little about java, and am stuck.
This seems wrong to me Don. Why would this code run again after the very first call? It should be running 1 time after which you have a reference to your object. What does the rest of your application.cfm look like? Have you added a cfapplication tag with a "name"?
If you fail to set an application "name" (via the cfapplication tag or "this.name" in application.cfc), the an "application.x" variable is treated just like a regular variable. After the page request ends it will "go away" and require the next request to reinstantiate the object over again.
The purpose of the "isDefined()" in this case is to insure it runs only once - providing you with a singleton (single reference) you can use again and again without reinstantiating it. It sounds like you are not "inside" an application.

Debugging a Photo Uploader/ CfCatch

I seem to be having an issue with the photo uploading function on a site I'm working on.
<cftry>
<cffile
action="upload"
destination="#physicalPath#\PHOTOS"
filefield="photo"
nameconflict="makeunique"
accept="image/jpeg, image/pjpeg"
result="mypicture"
/>
<cfset OutcomeID = "#FORM.OutcomeID#"/>
<!---Inserts file name and outcome id into Uploads table in the database --->
<cfinvoke component="#classpath#.cf_classes.dao.uploads" method="insertPhoto" returnvariable="success">
<cfinvokeargument name="fileName" value="#mypicture.SERVERFILE#"/>
<cfinvokeargument name="OutcomeID" value="#OutcomeID#"/>
</cfinvoke>
<cfset photoError = "Photo uploaded successfully"/>
<cfcatch type="any">
<cfset photoError = "There was an error uploading your photo.<br/> Please make sure it is a JPEG format."/>
</cfcatch>
</cftry>
No matter what, I just keep getting back the error message defined in the cfCatch. What are some good ways to troubleshoot something like this? Do any problems stand out to anyone?
Thanks for the help, I'm still relatively new to CF.
You're masking the exception that your cfcatch is catching by just setting a string in there. If you don't want to remove your exception handler, a quick and easy way to see what the underlying error is while you're still working on the code is to add:
<cfcatch><cfdump var="#cfcatch#"></cfcatch>
You may want to add an abort="true" to your cfcatch to stop processing of further code at that point which can mask your exception dump or cause it not to appear.
Putting cfcatch.message into a string that the user sees is not good practice as this may potentially result in information disclosure which can be a security risk (eg. if the message contains a file path on your server or similar)
Long term, if you're using Coldfusion Builder then you can also use the Coldfusion Debugger that is built in to step through your code and see where it is failing at the state of your variables at that point.