clach04 avatar clach04 committed 1dba091

Added retry logic to Windows (only) JAMSHELL file creation code.

We've seen problems with VMWare (ESX) virtual machines under Windows (2003 and 7) where the unlink of the sub batch file succeeded BUT file creation of the same file name fails with (errno=13) permission denied. Occurs on both single and multiple CPU machines, in each case Jam was being ran with number of jobs of 1 (-j1), i.e. not a parallel jam build. This appears to be some sort of odd race condition in VMWare/Windows, every time this happens the file delete was fine. Retry logic is simply try-five-times (but quit if failure is not access denied) with a small sleep.

The logic could be extended to a configurable retry and even a progressively longer sleep but this has not been needed yet.

Comments (0)

Files changed (1)

 
 	if( p && *p || strlen( string ) > MAXLINE || shell )
 	{
-	    FILE *f;
+	    FILE *f = NULL;
+	    int retry = 5;
 
 	    /* Write command to bat file. */
 
-	    f = fopen( cmdtab[ slot ].tempfile, "w" );
+	    while (f == NULL && retry-- >= 0)
+	    {
+	        f = fopen( cmdtab[ slot ].tempfile, "w" );
+	        if (f == NULL)
+	            if (errno == EACCES)
+	            {
+	                printf("Jam EACCES creating shell batch file, %s, retry %d sleep\n", cmdtab[ slot ].tempfile, retry);
+	                Sleep(100);
+	            }
+	            else
+	                break;
+	    }
 	    if (f == NULL)
 	    {
 	        printf("Unable to open file %s for writing, errno = %d\n", cmdtab[ slot ].tempfile, errno);
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.