[Mono-list] Easy way to deadlock Mono with concurrent HttpWebRequests

Miguel de Icaza miguel at microsoft.com
Tue Jan 10 21:58:34 UTC 2017

This works for me, with both stable and master from December 12th.


From: Mono-list <mono-list-bounces at lists.dot.net> on behalf of Rubén de Alba <rdealba at codicesoftware.com>
Date: Friday, December 23, 2016 at 6:27 AM
To: "mono-list at lists.dot.net" <mono-list at lists.dot.net>
Cc: "psantosl at codicesoftware.com" <psantosl at codicesoftware.com>
Subject: [Mono-list] Easy way to deadlock Mono with concurrent HttpWebRequests


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/<https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.mono-project.com%2Farchived%2Farticlethreadpool_deadlocks%2F&data=02%7C01%7Cmiguel%40microsoft.com%7C9fa698bca9f44310f44d08d42b26b563%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636180892637291812&sdata=%2BSrNzQ4qjxdxSjyZltlqdwN%2BgfHhZORprCNzkNXdSrk%3D&reserved=0>

I have attached a small sample application to reproduce the issue. It occasionally deadlocks on Mono (and older) 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.
* CPU is very high (90% on my test box).
* After a while sometimes the entire program hangs.
* 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.

Any hints or workarounds will be greatly appreciated :-P



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.dot.net/pipermail/mono-list/attachments/20170110/d3b1193c/attachment.html>

More information about the Mono-list mailing list