5 Replies Latest reply on Jun 16, 2006 2:35 AM by edgriffiths

    Waiting for file lock release?

      I currently have a CF-enabled page running along with an administrative page which is used to manage files and directories being shown by the main page. Running latest version of CFMX on a Windows 2003 server. I've noticed, on occasion, when I try to delete a file using the admin app, I receive an error paraphrased as "You cannot delete file C:\myDirectory\myPicture.jpg for some unknown reason". A second later when I try again it works. I have come to the realization that the two apps are butting heads when it comes to system file locks. While the main page is serving a picture to be displayed, it understandably locks the file for a time (seems longer than it really needs to, though). The admin page comes along and wants to delete the same file and can't because the other page has it locked down in the system. Not using <CFLOCK> tag anywhere in the code.

      My question is this: Is there a way that my admin page can wait in a loop until the file lock is released by the main page in order to delete the file without ever throwing an error?

      I cannot seem to find anything on this but have noticed others mention this problem. Any assistance appreciated.
        • 1. Waiting for file lock release?
          jdeline Level 1
          You could place a read-only lock around the code that displays the image, and an exclusive lock around the code that does the delete. If the picture is being displayed, the deletion code will wait until the read-only lock is released.
          • 2. Re: Waiting for file lock release?
            j.stevenson Level 1
            I fear this may have a deleterious effect on performance. To do an extra lock on each file as it's being served, in addition to the system file lock, may slow performance to unacceptible levels. Particularly since there are a large number of thumbnails being loaded and displayed on the main page (apologies for not mentioning that in my initial post). I would think putting the admin app in a loop until the system file lock is released before doing anything to the file in question would be a much more efficient use of cycles in this particular scenario. Any other thoughts out there?
            • 3. Re: Waiting for file lock release?
              Mr Black Level 1
              If you are sure that this is a file-sharing problem, something very basic could work. For example,

              <!--- Attempt to delete file --->
              <!--- Make a pause for N seconds and try again --->
              • 4. Re: Waiting for file lock release?
                Stefan_K. Level 1
                I'd go with Mr. Black.

                You could also try to rename the fale ( rename it back) to test if the file is locked.

                If waiting for the file to become unlocked is slowing down performance, you could outsource the delete-file operation into a separate file, call that by cfhttp with a low cfhttp-timeout but a high request-timeout.
                That way your application does not have to wait since the delete-file process (with waiting, etc.) is running in separate request on the server. Of course you would not know when the file is actually being deleted, but you don't have to wait for it either.
                p.s. "Separate file called by cfHTTP" could be a webservice nowadays.
                • 5. Re: Waiting for file lock release?
                  edgriffiths Level 1
                  if you're running Enterprise edition, the delete function sounds like a job that should be delegated to an Asynchronous Event Gateway.