Bug 51189 - Easy way to deadlock Mono with concurrent HttpWebRequests
Summary: Easy way to deadlock Mono with concurrent HttpWebRequests
Status: NEW
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Net.Http (show other bugs)
Version: 4.8.0 (C9)
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-01-03 12:37 UTC by rubarax
Modified: 2017-01-03 12:37 UTC (History)
1 user (show)

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


Attachments
Application code (2.45 KB, text/plain)
2017-01-03 12:37 UTC, rubarax
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 51189 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description rubarax 2017-01-03 12:37:19 UTC
Created attachment 19066 [details]
Application code

We can deadlock Mono launching a few HttpWebRequests. We can consistently reproduce in our app, but only sometimes happens in the attached program.

We initially detected this on a server pulling data from Azure. It deadlocks and it is unable to handle a single new request (since we rely on Socket.BeginReceive for that, and the callback is never invoked once the deadlock happens).

We suspect it could still be related to this ancient issue: http://www.mono-project.com/archived/articlethreadpool_deadlocks/

I have attached a small sample application to reproduce the issue. It occasionally deadlocks on Mono 4.6.2.7 / 4.8.0.395 no matter whether the machine has 1 core or 8. What is consistent is that it performs worse than expected and fails. Not sure if this is a hint.

What the app does is:

* It launches 40 HttpWebRequest.GetResponse() in parallel.
* Most of them fail ("The authentication or decryption has failed.", "The request timed out") .
* The program retries if they fail - and retries also fail.
* Too high cpu usage (30% on my test box).
* We also tried the HttpClient class using async calls and no threadpool but result wasn't any better. 

Some interesting notes:
* The same code works well in .NET/Windows.
* And launching the 40 concurrent requests is super fast there compared to super slow using Mono.

* It works better with mono-4.0.4 (it ends faster and without errors)
* Running mono with the '--server' flag doesn't make any difference.