Skip to content

FileDownloader's providedClient is used concurrently thus can throw "WebClient does not support concurrent I/O operations" #880

Open
@szanto90balazs

Description

@szanto90balazs

I'm getting exceptions originating from UpdateManager.DownloadReleases with the following message

WebClient does not support concurrent I/O operations

and it's because I use my own ✨WebClient✨ instance.

In the FileDownloader's constructor a WebClient providedClient can be specified. Because UpdateManager.DownloadReleases downloads the packages parallel, FileDownloader.DownloadFile can be called concurrently, which uses a "singleton" WebClient concurrently, however WebClient only supports a single operation, it cannot download multiple files at once, that's why it's throwing exceptions.

The file downloader works by default because Utility.CreateWebClient(); is called on every DownloadFile.

public class FileDownloader : IFileDownloader, IEnableLogger
{
    private readonly WebClient _providedClient;

    public FileDownloader(WebClient providedClient = null)
    {
        this._providedClient = providedClient;
    }

    public async Task DownloadFile(string url, string targetFile, Action<int> progress)
    {
        WebClient wc = this._providedClient ?? Utility.CreateWebClient();
        
        ...

I can workaround this in my codebase, but I'd like to change it in Squirrel to something like this below. What do you think?

public class FileDownloader : IFileDownloader, IEnableLogger
{
    private readonly Func<WebClient> _webClientFactory;

    public FileDownloader(Func<WebClient> providedClientFactory = null)
    {
        this._webClientFactory = providedClientFactory ?? Utility.CreateWebClient
    }

    public async Task DownloadFile(string url, string targetFile, Action<int> progress)
    {
        WebClient wc = _webClientFactory(); 
        
        ...

Activity

shiftkey

shiftkey commented on May 5, 2019

@shiftkey
Contributor

Related to #886

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature:requestedSuggestions to enhance the library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Participants

    @shiftkey@szanto90balazs

    Issue actions

      FileDownloader's providedClient is used concurrently thus can throw "WebClient does not support concurrent I/O operations" · Issue #880 · Squirrel/Squirrel.Windows