Skip to content

Commit

Permalink
clean (FileDownloader.cs, FileUploader.cs): we now increase suspiciou…
Browse files Browse the repository at this point in the history
…sTransportFailuresCount if and only if we're not dealing with a show-stopper error
  • Loading branch information
ksidirop-laerdal committed Oct 18, 2024
1 parent 9774f58 commit ae9942e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
10 changes: 5 additions & 5 deletions Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,6 @@ public async Task<byte[]> DownloadAsync(
}
catch (DownloadErroredOutException ex)
{
if (fileDownloadProgressEventsCount <= 10)
{
suspiciousTransportFailuresCount++;
}

if (ex is DownloadErroredOutRemoteFileNotFoundException) //order no point to retry if the remote file is not there
{
//OnStateChanged(new StateChangedEventArgs(newState: EFileDownloaderState.Error)); //noneed already done in native code
Expand All @@ -283,6 +278,11 @@ public async Task<byte[]> DownloadAsync(
//OnStateChanged(new StateChangedEventArgs(newState: EFileDownloaderState.Error)); //noneed already done in native code
throw new AllDownloadAttemptsFailedException(remoteFilePath, maxTriesCount, innerException: ex);
}

if (fileDownloadProgressEventsCount <= 10)
{
suspiciousTransportFailuresCount++;
}

if (sleepTimeBetweenRetriesInMs > 0) //order
{
Expand Down
16 changes: 7 additions & 9 deletions Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -314,17 +314,17 @@ public async Task UploadAsync<TData>(
}
catch (UploadErroredOutException ex) //errors with code in_value(3) and even UnauthorizedException happen all the time in android when multiuploading files
{
if (fileUploadProgressEventsCount <= 10)
{
suspiciousTransportFailuresCount++;
}

if (ex is UploadErroredOutRemoteFolderNotFoundException) //order no point to retry if any of the remote parent folders are not there
throw;

if (++triesCount > maxTriesCount) //order
throw new AllUploadAttemptsFailedException(remoteFilePath, maxTriesCount, innerException: ex);

if (fileUploadProgressEventsCount <= 10)
{
suspiciousTransportFailuresCount++;
}

if (sleepTimeBetweenRetriesInMs > 0) //order
{
await Task.Delay(sleepTimeBetweenRetriesInMs);
Expand Down Expand Up @@ -369,8 +369,7 @@ void FileUploader_FileUploaded_(object _, FileUploadedEventArgs ea_)
taskCompletionSource.TrySetResult(true);
}

// ReSharper disable AccessToModifiedClosure
void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_)
void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_) // ReSharper disable AccessToModifiedClosure
{
switch (ea_.NewState)
{
Expand Down Expand Up @@ -409,7 +408,7 @@ void FileUploader_StateChanged_(object _, StateChangedEventArgs ea_)

//00 we first wait to allow the cancellation to be handled by the underlying native code meaning that we should see OnCancelled()
// getting called right above but if that takes too long we give the killing blow by calling OnCancelled() manually here
}
} // ReSharper restore AccessToModifiedClosure

void FileUploader_FileUploadProgressPercentageAndDataThroughputChanged_(object sender, FileUploadProgressPercentageAndDataThroughputChangedEventArgs ea)
{
Expand Down Expand Up @@ -440,7 +439,6 @@ void FileUploader_FatalErrorOccurred_(object sender, FatalErrorOccurredEventArgs
)
});
}
// ReSharper restore AccessToModifiedClosure
}

if (isCancellationRequested) //vital
Expand Down
6 changes: 3 additions & 3 deletions Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,13 +234,13 @@ public async Task InstallAsync(
}
catch (FirmwareInstallationUploadingStageErroredOutException ex) //we only want to retry if the errors are related to the upload part of the process
{
if (++triesCount > maxTriesCount) //order
throw new AllFirmwareInstallationAttemptsFailedException(maxTriesCount, innerException: ex);

if (_fileUploadProgressEventsCount <= 10)
{
suspiciousTransportFailuresCount++;
}

if (++triesCount > maxTriesCount) //order
throw new AllFirmwareInstallationAttemptsFailedException(maxTriesCount, innerException: ex);

if (sleepTimeBetweenRetriesInMs > 0) //order
{
Expand Down

0 comments on commit ae9942e

Please sign in to comment.