Copy link to clipboard
Copied
Hello,
I had Encountered couple of issues after update ColdFusion 2023 Update 5 to Update 10.
1. ColdFusion could not delete the file C:\Request Form1.pdf. . The cause of this exception was: java.nio.file.FileSystemException: Request Form1.pdf: The process cannot access the file because it is being used by another process. <br>The error occurred on line 8.
below is the code. When I add the <cfset sleep(500) /> before a file deletion then it works fine.
<cffile action="readbinary" file="#filelocation#" variable="clobVar" />
<cffile action="delete" file="#filelocation#">
2. It seems some of the configuration missed related to custom Java class for below code I am getting an error as "Object Instantiation Exception. Class not found: org.util.pdf.AppendLetterPDFs <br>The error occurred on line 32." for below code. But I am not sure where the Jar or packages mapped or configured.
<CFOBJECT ACTION="CREATE" TYPE="JAVA" NAME="appender" CLASS="org.util.pdf.AppendLetterPDFs">
can anyone please help on this.
Hi,
Your explanation of issue 1. actually contains a hint. The issue arises because the process <cffile action="delete"> may attempt to start before the process <cffile action="readbinary"> ends. When that happens, the delete process cannot then have access to the file at #fileLocation#. That is because. the reading process would still be holding a lock on the file. The code works with sleep(500) because this enables the read process to finish.
Why would you need to read from a file just befor
...Copy link to clipboard
Copied
Hi,
Your explanation of issue 1. actually contains a hint. The issue arises because the process <cffile action="delete"> may attempt to start before the process <cffile action="readbinary"> ends. When that happens, the delete process cannot then have access to the file at #fileLocation#. That is because. the reading process would still be holding a lock on the file. The code works with sleep(500) because this enables the read process to finish.
Why would you need to read from a file just before deleting it anyway? If there is no need for the readBinary process, then delete that line.
However, if you need to read the file (and use the information obtained from reading), then you should separate the two processes with a named lock, as follows:
<cflock timeout="10" name="MyFileReadAndDeleteLock" type="readonly">
<cffile action="readbinary" file="#filelocation#" variable="clobVar" />
<!--- Here goes the code that uses the information that has been read --->
</cflock>
<cflock timeout="5" name="MyFileReadAndDeleteLock" type="exclusive">
<cffile action="delete" file="#filelocation#">
</cflock>
The cause of issue 2. is obvious. ColdFusion cannot find the class org.util.pdf.AppendLetterPDFs. In fact, neither can Google:
So, org.util.pdf.AppendLetterPDFs is very likely situated in a custom Jar file.
Locate the Jar file in your file system. Copy it to cfusion/lib or {YOUR_COLDFUSION_INSTANCE}/lib, making sure that just one version of the fle is available to ColdFusion. Finally, restart ColdFusion.
Copy link to clipboard
Copied
Thanks @BKBK .
2 is working after restored my jar file.
1 is working when I update the ColdFusion Version from CF 2023 10 to 5. Again if I update a version from CF 2023 update 5 to 10 then encoumtering the error "java.nio.file.FileSystemException: Request Form1.pdf: The process cannot access the file because it is being used by another process. <br>The error occurred on line 8." ------ I want to understand CF 2023 update 6 to 10 is their any change in cffile behavior
Copy link to clipboard
Copied
The way CFML interacts with the file system is kind of complicated, and it very well may have changed between updates. But I suggest that instead of trying to figure out the underlying root cause, you modify your code per @BKBK 's suggestions and move on. Reading and deleting files sequentially can cause trouble. There are other ways you could deal with this problem, too. For example, you could choose not to delete the file immediately, then have a scheduled process delete all the undeleted files if there aren't any in use, or delete the files you know aren't in use, etc.
Dave Watts, Eidolon LLC
Copy link to clipboard
Copied
@Dave Watts Thanks for Clarifing this. This is helpfull.
Copy link to clipboard
Copied
@kkmr2011 , to answer your last question, yes, there is definitely a change of tradition in ColdFusion. In recent years, newer versions and updates tend to be stricter, more accurate and less tolerant of bad-practice.
So you are actually lucky to get the error now, instead of later in production. Reading from a file, then proceeding to delete it within the same page-context, is bad-practice in any programming language. Hence the need for a lock.
Copy link to clipboard
Copied
@BKBK , Thanks much on your inputs. This will helps and I will apply the changes to the code.