Bug 52555 - WebClient.DownloadString not returning inside a task
Summary: WebClient.DownloadString not returning inside a task
Status: NEEDINFO
Alias: None
Product: Class Libraries
Classification: Mono
Component: System (show other bugs)
Version: 4.6.0 (C8)
Hardware: PC All
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-02-16 06:43 UTC by sidcup
Modified: 2017-04-03 15:45 UTC (History)
3 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments

Description sidcup 2017-02-16 06:43:49 UTC
I'm trying to use a webclient inside a task, see for code: http://stackoverflow.com/questions/42265198/cannot-get-webclient-downloadstring-to-download-inside-a-task-on-mono

The WriteLines are only to indicate where the task was delaying. The string is not returned and so "5" is not displayed. Instead I only receive timeouts. Why is this happening? It works without a hitch on .Net framework 4.5. It does not work on mono linux nor windows.

            var urls5 = urls.Take(100);
            var elapsed5 = Test<WebClient>(urls5);
            Console.WriteLine("Webclient:" + elapsed5);


        static TimeSpan Test<T>(IEnumerable<string> urls) where T : WebClient, new()
        {
            Console.WriteLine("1");
            var sw = new System.Diagnostics.Stopwatch();

            sw.Start();

            Console.WriteLine("2");
            var tasks = new List<Task>();

            foreach (var u in urls)
            {
                tasks.Add(Task.Run(() =>
                {
                    Console.WriteLine("3");
                    using (var wc = new T())
                    {
                        Console.WriteLine("4");
                        var str = wc.DownloadString(u);
                        Console.WriteLine("5");
                        var hap = new HtmlAgilityPack.HtmlDocument();
                        hap.LoadHtml(str);

                        var asdf = hap.DocumentNode.InnerText + " ";

                        Console.Write(".");
                    }
                }));
            }

            Task.WaitAll(tasks.ToArray());

            sw.Stop();
            return sw.Elapsed;
        }
Comment 1 sidcup 2017-02-16 07:29:08 UTC
A little background info, the HtmlAgilityPack code is part of a bigger project trying to trackdown what I think is a further issue where code pulling and processing data appears to be significantly faster on Windows than linux/mono (on a server where wget can pull the data down at blistering speeds). This is a separate issue that I will focus on after this issue is dealt with.
Comment 2 Marek Safar 2017-04-03 15:45:14 UTC
Could you attach complete repro we can use to reproduce?

Note You need to log in before you can comment on or make changes to this bug.