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)

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


Attachments

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!

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