I observed intermittent errors on several systems that I worked on using the same methodology (not the same code), which made me think that the problem could be related to creating and using structures in the same query. I wonder if a race condition is possible there?
The scenario is this: We are in an e-commerce system looking at a product or, in some cases, a list of products. This code is designed to return images associated with each product in a structure that we can use to display the specified images.
At the beginning of the query, the code searches for database records associated with the item in question. These entries are images for the product (s). These records are returned by a single call CFQuery(or, more precisely, by a call to a function that returns the results of a call CFQueryformed into a structure containing various information).
Then the code goes through the provided image structure and adds various information to the local structure. Later in the request, we use the data in the structure to display images in our tags <img>. We also populate the tag with <img>attributes data-for use with JavaScript.
In the event that any particular image was not returned correctly by the request - usually due to the lack of a physical file - we use a common placeholder image. This is done by placing the structure in a block try/catch.
Important: it works.
However, this happens very often, when we refer to the node in the structure we created, we find that it does not exist, and CF throws an error - it may be, perhaps 1% of the time and reloading on the same page will work fine.
, , ColdFusion ( 8 10) .
, , FileExists, , , , , , , , - - .
, , , , ; node , . threading , , , ... .
, , , , , , , , .
<cfset Local.stProductImages = Application.cfcParts.getPartImages(
l_iItemID = Arguments.pid
) />
<cfloop list="#ListSort(structKeyList(Local.stProductImages['item_' & Arguments.pid]), 'text')#" index="i">
<cftry>
<cfset Local['ImageURL_' & i & '_Large'] = Local.stProductImages['item_' & Local.arguments.pid][i].large_watermarked.URL />
<cfcatch>
<cfset Local['ImageURL_' & i & '_Large'] = Application.com.Images.getMissingImages().large />
</cfcatch>
</cftry>
<cftry>
<cfset Local['ImageURL_' & i & '_Med'] = Local.stProductImages['item_' & Local.arguments.pid][i].med.URL />
<cfcatch>
<cfset Local['ImageURL_' & i & '_Med'] = Application.com.Images.getMissingImages().med />
</cfcatch>
</cftry>
<cftry>
<cfset Local['ImageURL_' & i & '_Small'] = Local.stProductImages['item_' & Local.arguments.pid][i].small.URL />
<cfcatch>
<cfset Local['ImageURL_' & i & '_Small'] = Application.com.Images.getMissingImages().small />
</cfcatch>
</cftry>
<img class = "altProdImg<cfif i EQ 'image_03'> endImage</cfif>"
src = "#Local['ImageURL_' & i & '_Small']#"
image = "#i#"
alt = ""
data-imgsmall = "#Local['ImageURL_' & i & '_Small']#"
data-imgmed = "#Local['ImageURL_' & i & '_Med']#"
data-imglarge = "#Local['ImageURL_' & i & '_Large']#"
data-imgnum = "#i#"
data-pid = "#Arguments.pid#"
/>
</cfloop>
<img> node, , - - :
ImageURL_image_02_Large undefined Java class coldfusion.runtime.LocalScope.
... , .
... , - , ?