Browse code

Fixing retry hack for TP4 to return errors in all failure cases.

Signed-off-by: Stefan J. Wernli <swernli@microsoft.com>

Stefan J. Wernli authored on 2016/02/26 10:54:13
Showing 1 changed files
... ...
@@ -238,33 +238,30 @@ func (d *Driver) Run(c *execdriver.Command, pipes *execdriver.Pipes, hooks execd
238 238
 	// TODO Windows TP5 timeframe. Remove when TP4 is no longer supported.
239 239
 	// The following a workaround for Windows TP4 which has a networking
240 240
 	// bug which fairly frequently returns an error. Back off and retry.
241
-	maxAttempts := 1
242
-	if TP4RetryHack {
243
-		maxAttempts = 5
244
-	}
245
-	i := 0
246
-	for i < maxAttempts {
247
-		i++
241
+	maxAttempts := 5
242
+	for i := 0; i < maxAttempts; i++ {
248 243
 		err = hcsshim.CreateComputeSystem(c.ID, configuration)
249
-		if err != nil {
250
-			if TP4RetryHack {
251
-				if herr, ok := err.(*hcsshim.HcsError); ok {
252
-					if herr.Err != syscall.ERROR_NOT_FOUND && // Element not found
253
-						herr.Err != syscall.ERROR_FILE_NOT_FOUND && // The system cannot find the file specified
254
-						herr.Err != ErrorNoNetwork && // The network is not present or not started
255
-						herr.Err != ErrorBadPathname && // The specified path is invalid
256
-						herr.Err != CoEClassstring && // Invalid class string
257
-						herr.Err != ErrorInvalidObject { // The object identifier does not represent a valid object
258
-						logrus.Debugln("Failed to create temporary container ", err)
259
-						return execdriver.ExitStatus{ExitCode: -1}, err
260
-					}
261
-					logrus.Warnf("Invoking Windows TP4 retry hack (%d of %d)", i, maxAttempts-1)
262
-					time.Sleep(50 * time.Millisecond)
263
-				}
264
-			}
265
-		} else {
244
+		if err == nil {
266 245
 			break
267 246
 		}
247
+
248
+		if !TP4RetryHack {
249
+			return execdriver.ExitStatus{ExitCode: -1}, err
250
+		}
251
+
252
+		if herr, ok := err.(*hcsshim.HcsError); ok {
253
+			if herr.Err != syscall.ERROR_NOT_FOUND && // Element not found
254
+				herr.Err != syscall.ERROR_FILE_NOT_FOUND && // The system cannot find the file specified
255
+				herr.Err != ErrorNoNetwork && // The network is not present or not started
256
+				herr.Err != ErrorBadPathname && // The specified path is invalid
257
+				herr.Err != CoEClassstring && // Invalid class string
258
+				herr.Err != ErrorInvalidObject { // The object identifier does not represent a valid object
259
+				logrus.Debugln("Failed to create temporary container ", err)
260
+				return execdriver.ExitStatus{ExitCode: -1}, err
261
+			}
262
+			logrus.Warnf("Invoking Windows TP4 retry hack (%d of %d)", i, maxAttempts-1)
263
+			time.Sleep(50 * time.Millisecond)
264
+		}
268 265
 	}
269 266
 
270 267
 	// Start the container