Random Error While Building - "The process cannot access the file because it is being used by another process"
Posted: Thu Mar 09, 2017 9:43 am
So I have had this random error previously with older editions of IA. But I am getting them more and more often now and my installers are more complex than they were before. They also appear to happen at random points during the build process, usually closer to the start of the build. Images show examples of the build failing but progressing a little further each time.
Running IA as an Administrator does nothing to change this behavior. (While the randomness of the errors might lead to a problem in IA itself, and I do not notice a rise in activity of the various anti-whatever stuff running on my machine, the remainder of this post assumes that IA is not the cause of the problem.)
Previously any posts on this forum regarding file access problems tends to be responded to with something along the lines of "check or disable your anti-virus/anti-malware/anti-DLP software."
Quite frankly, that is just not good enough anymore. Users may exist in an I.T. environment where they cannot simply "turn things off." Additionally, unless that is shown as a disclaimer before one purchases licenses for the product, it cannot be used as a catch-all excuse after purchase.
The software needs to be tolerant of temporary/occasional file access problems and work around them. Having to write a script to build an installer from the command line in a loop over and over again until it succeeds is a waste of time and should be unnecessary with modern software, especially when the support personnel are aware of a problem, and should have informed the developers by now.
However, being an experienced software developer, I am not going to simply complain about the problem and not offer possible solutions. So here are some suggestions:
1: Automatically retry all file accesses. This is the most important one - since the errors happen at random places, it stands to reason that retrying might help. Thus, all file access should be wrapped in such a way that automatic retries are tried after a small delay and then only give up once a certain number of file accesses have failed. Both the retry/wait interval and the number of retries should be configurable by the end user. Even Visual Studio retries 10 times before giving up - let this be a good example.
2: Ensure minimal file and sharing access is requested when opening files. In Windows, this has been a problem for as long as the CreateFile(...) function has been around. Make sure that if you are opening a file just to read its contents that you are specifying appropriate access and share values to maximize the chances of being able to open the file successfully. For example, do not specify GENERIC_ALL if you are just opening the file to read it. If you only need to read it, make sure your share flags do not include write access. In a tightly-controlled environment, maybe even specifying specific access flags instead of GENERIC_READ may be necessary. If it will work in a tightly-controlled environment, it will work elsewhere.
3: Show the user which process has the file locked! This is the ultimate and should be done if no other option is exercised. Many (many, MANY) moons ago I wrote a product called DeleteFXPFiles that would walk kernel objects in Windows XP to determine which process(es) held a file open that you were trying to delete. So I know it is possible to do this, and there is no real excuse not to. There are easier ways to do this today (e.g. the Restart Manager), and this should be implemented to help users determine the actual cause of a problem and then they have some ammunition to take to the I.T. department if necessary, or to help identify bugs or other unwanted behavior in IA or some other software.
I would hope that these suggestions would find their way to the development staff. These are not hard things to implement, and can only help improve the software.
We love IA here - but it is worthless if we cannot build consistently with it.
Running IA as an Administrator does nothing to change this behavior. (While the randomness of the errors might lead to a problem in IA itself, and I do not notice a rise in activity of the various anti-whatever stuff running on my machine, the remainder of this post assumes that IA is not the cause of the problem.)
Previously any posts on this forum regarding file access problems tends to be responded to with something along the lines of "check or disable your anti-virus/anti-malware/anti-DLP software."
Quite frankly, that is just not good enough anymore. Users may exist in an I.T. environment where they cannot simply "turn things off." Additionally, unless that is shown as a disclaimer before one purchases licenses for the product, it cannot be used as a catch-all excuse after purchase.
The software needs to be tolerant of temporary/occasional file access problems and work around them. Having to write a script to build an installer from the command line in a loop over and over again until it succeeds is a waste of time and should be unnecessary with modern software, especially when the support personnel are aware of a problem, and should have informed the developers by now.
However, being an experienced software developer, I am not going to simply complain about the problem and not offer possible solutions. So here are some suggestions:
1: Automatically retry all file accesses. This is the most important one - since the errors happen at random places, it stands to reason that retrying might help. Thus, all file access should be wrapped in such a way that automatic retries are tried after a small delay and then only give up once a certain number of file accesses have failed. Both the retry/wait interval and the number of retries should be configurable by the end user. Even Visual Studio retries 10 times before giving up - let this be a good example.
2: Ensure minimal file and sharing access is requested when opening files. In Windows, this has been a problem for as long as the CreateFile(...) function has been around. Make sure that if you are opening a file just to read its contents that you are specifying appropriate access and share values to maximize the chances of being able to open the file successfully. For example, do not specify GENERIC_ALL if you are just opening the file to read it. If you only need to read it, make sure your share flags do not include write access. In a tightly-controlled environment, maybe even specifying specific access flags instead of GENERIC_READ may be necessary. If it will work in a tightly-controlled environment, it will work elsewhere.
3: Show the user which process has the file locked! This is the ultimate and should be done if no other option is exercised. Many (many, MANY) moons ago I wrote a product called DeleteFXPFiles that would walk kernel objects in Windows XP to determine which process(es) held a file open that you were trying to delete. So I know it is possible to do this, and there is no real excuse not to. There are easier ways to do this today (e.g. the Restart Manager), and this should be implemented to help users determine the actual cause of a problem and then they have some ammunition to take to the I.T. department if necessary, or to help identify bugs or other unwanted behavior in IA or some other software.
I would hope that these suggestions would find their way to the development staff. These are not hard things to implement, and can only help improve the software.
We love IA here - but it is worthless if we cannot build consistently with it.