@@ -577,17 +577,19 @@ let rec private _safeGetFromUrl (auth:Auth option, url : string, contentType : s
577577
578578 use timeoutTok = new System.Threading.CancellationTokenSource()
579579 timeoutTok.CancelAfter( 60000 )
580+ let shouldRetry () =
581+ iTry < nTries
580582 let shouldRetryTimeout exn =
581583 let exnNames = getExceptionNames exn
582- iTry < nTries &&
584+ shouldRetry () &&
583585 ( timeoutTok.IsCancellationRequested && ( exnNames |> List.contains " OperationCanceledException" ))
584586
585587 async {
586588 try
587589 let uri = Uri url
588590 use client = createHttpClient ( url, auth)
589591 let! tok = Async.CancellationToken
590- let tokSource = System.Threading.CancellationTokenSource.CreateLinkedTokenSource( tok, timeoutTok)
592+ let tokSource = System.Threading.CancellationTokenSource.CreateLinkedTokenSource( tok, timeoutTok.Token )
591593
592594 if notNullOrEmpty contentType then
593595 addAcceptHeader client contentType
@@ -599,10 +601,14 @@ let rec private _safeGetFromUrl (auth:Auth option, url : string, contentType : s
599601 return SuccessResponse raw
600602 with
601603 | exn when shouldRetryTimeout exn ->
602- Logging.traceWarnfn " Request to '%O ' didn't respond after 60 seconds, trying again %i /%i " uri iTry nTries
604+ Logging.traceWarnfn " Request to '%s ' didn't respond after 60 seconds, trying again %i /%i " url iTry nTries
605+ return ! _ safeGetFromUrl( auth, url, contentType, iTry + 1 , nTries)
606+ | : ? HttpRequestException as req when ( shouldRetry () && ( req .InnerException :? System .Net .Sockets .SocketException )) ->
607+ Logging.traceWarnfn " Request to '%s ' failed with '%s ', trying again %i /%i " url req.Message iTry nTries
603608 return ! _ safeGetFromUrl( auth, url, contentType, iTry + 1 , nTries)
604609 | : ? OperationCanceledException as cancel when timeoutTok .IsCancellationRequested ->
605- raise ( Exception( sprintf " Request to '%O ' finally timed out after 60 seconds after several retries" uri, exn))
610+ let msg = sprintf " Request to '%s ' finally timed out after 60 seconds after several retries" url
611+ return raise ( Exception( msg, cancel))
606612 | : ? RequestFailedException as w ->
607613 match w.Info with
608614 | Some { StatusCode = HttpStatusCode.NotFound } -> return NotFound
0 commit comments