Prechádzať zdrojové kódy

Capture last error in inproxy.DialClient retry loop

Rod Hynes 11 mesiacov pred
rodič
commit
bf246fc830
1 zmenil súbory, kde vykonal 8 pridanie a 0 odobranie
  1. 8 0
      psiphon/common/inproxy/client.go

+ 8 - 0
psiphon/common/inproxy/client.go

@@ -207,6 +207,8 @@ func DialClient(
 	}
 
 	var result *clientWebRTCDialResult
+	var lastErr error
+
 	for attempt := 0; ; attempt += 1 {
 
 		previousAttemptsDuration := time.Since(startTime)
@@ -226,6 +228,10 @@ func DialClient(
 
 		err := ctx.Err()
 		if err != nil {
+			if lastErr != nil {
+				err = fmt.Errorf(
+					"%w, attempts: %d, lastErr: %w", err, attempt, lastErr)
+			}
 			return nil, errors.Trace(err)
 		}
 
@@ -245,6 +251,8 @@ func DialClient(
 			break
 		}
 
+		lastErr = err
+
 		if retry {
 			config.Logger.WithTraceFields(common.LogFields{"error": err}).Warning("dial failed")