Skip to content

Cannot download multiple OneDrive files concurrently since v.1.13.0-beta #413

@tipa

Description

@tipa

Expected behavior

Until and including v1.12.0 I was able to download many files from OneDrive concurrently (see code snippet below) without any issues (and fast!).

Actual behavior

Since v1.13.0-beta (and incl. the now available v1.14.0) the download of multiple OneDrive files is slow from the beginning and is getting even slower over time. The app can only download up to ~15 files before the process eventually stops completely and the following exception is raised (no custom timeout set):

Code: generalExceptionMessage: An error occurred sending the request. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Exception: The text associated with this error code could not be found.The operation timed out at System.Net.Http.HttpHandlerToFilter.SendAsync(HttpRequestMessage request, CancellationToken cancel) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Graph.AuthenticationHandler.SendAsync(HttpRequestMessage httpRequestMessage, CancellationToken cancellationToken) at Microsoft.Graph.RetryHandler.SendAsync(HttpRequestMessage httpRequest, CancellationToken cancellationToken) at Microsoft.Graph.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Microsoft.Graph.HttpProvider.SendRequestAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) at Microsoft.Graph.BaseRequest.SendStreamRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) at Diarium.OneDriveHelper.DownloadFile(GraphServiceClient graphClient, String fileName)

Steps to reproduce the behavior

Microsoft.Graph v1.14.0
UWP app (but also happens in Xamarin)

var client = new GraphServiceClient("https://graph.microsoft.com/beta", new DelegateAuthenticationProvider(reqMsg =>
{
    reqMsg.Headers.Authorization = new AuthenticationHeaderValue("bearer", authResult.AccessToken);
    return Task.CompletedTask;
}));

SemaphoreSlim semaphore = new SemaphoreSlim(10);
if (filesToDownload.Count > 0)
{
    var downloadTasks = new List<Task>();
    var downloaded = 0; var error = false;
    foreach (var file in filesToDownload)
    {
        await semaphore.WaitAsync();
        if (error) { semaphore.Release(); break; }
        downloadTasks.Add(Task.Run(async () =>
        {
            try { file.Data = await DownloadFile(graphClient, file.Name); }
            catch { error = true; throw; }
            finally { semaphore.Release(); }
        }));
    }
    await Task.WhenAll(downloadTasks);
}


static async Task<byte[]> DownloadFile(GraphServiceClient graphClient, string fileName)
{
    using (var response = await graphClient.Drive.Special.AppRoot.ItemWithPath(fileName).Content.Request().GetAsync())
    {
        return Decrypt(response);
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions