Bug 36572 - HttpWebRequest giving “The request timed out” in Mono
Summary: HttpWebRequest giving “The request timed out” in Mono
Status: RESOLVED NORESPONSE
Alias: None
Product: Runtime
Classification: Mono
Component: General (show other bugs)
Version: 3.12.0
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-12-03 23:58 UTC by Christian Melendez
Modified: 2017-10-11 17:13 UTC (History)
5 users (show)

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

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 on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NORESPONSE

Description Christian Melendez 2015-12-03 23:58:37 UTC
When I make a request to another server it is throwing an execption with the error "The request timed out" and I can't make more requests to that site. I'm using ServiceStack v3 with SmarthThreadPool and I already have configured the MONO_THREADS_PER_CPU to 100 but we are facing this issue eventually. I imagine that the threads are not being disposed correctly so there comes a time when I can't create more requests (until we re boot the process because it's a self hosted app)

This is running on Ubuntu 14.04 with mono version 3.12.1, I also read that in the version 4.2 they fixed a lot of bugs with the ThreadPool, but I haven't test it in production yet. Any advice or suggestion? I'm out of ideas of what to do know and I'm still having downtimes of the API because of this.

Many, many thanks in advance :)

Here is the code I'm using:

private static string GetRawJson(string requestUrl, string ipAddress) {
        ServicePointManager.DefaultConnectionLimit = 1000;
        ServicePointManager.UseNagleAlgorithm = false;
        ServicePointManager.Expect100Continue = false;

        var requestResponse = string.Empty;
        var request = (HttpWebRequest) WebRequest.Create(requestUrl);
        request.Proxy = null;
        request.KeepAlive = true;
        request.Timeout = 800;
        request.Headers.Add("X-Forwarded-For", ipAddress);

        using (var response = request.GetResponse()) {
            using (var stream = response.GetResponseStream()) {
                if (stream != null) {
                    using (var reader = new StreamReader(stream)) {
                        requestResponse = reader.ReadToEnd();
                        reader.Close();
                    }
                    stream.Close();
                }                        
            }
            response.Close();
        }

        return requestResponse;
    }

We also switched to HttpClient instead but same issue (http://stackoverflow.com/questions/16194054/is-async-httpclient-from-net-4-5-a-bad-choice-for-intensive-load-applications).

Weird thing is that this is a microservice API and it fails just with external services, when doing requests to our service discovery we don't face this kind of issues neither when doing a direct request through the IP address to another microservice.
Comment 1 Marek Safar 2015-12-07 17:05:58 UTC
Please re-test with Mono 4.2 it has many fixes which could resolve your issue. If you can still reproduce the issue, please provide us tests how to reproduce it locally.
Comment 2 Rodrigo Kumpera 2017-10-11 17:13:38 UTC
We have not received the requested information. If you are still experiencing this issue please provide all the requested information and reopen the bug report.

Thank you!