2

I'm having a problem connecting to a 3rd party API using the DevDefined OAuth library for C#:

https://github.com/bittercoder/DevDefined.OAuth

The connection has been working fine for over a year now, but in the last two days it has started failing every few hours. The exception message is:

The request was aborted: Could not create SSL/TLS secure channel 

It works as normal after the app pool has been restarted but then stops authenticating after a few hours - this makes me think that it is not closing the HttpWebRequest, and we are leaking connections and eventually running out.

A similar question suggests that KeepAlive might solve this, but it did not help me: ASP.NET - The request was aborted: Could not create SSL/TLS secure channel

But the code is quite complex, and the HttpWebRequest object is passed around to many other functions after being created. I can't see where to close it. And also, I don't know how to close a HttpWebRequest, so my question is:

  • How can I find where to close this HttpWebRequest?
  • How do you close a HttpWebRequest? Or is it the Response that must be disposed?

The DevDefined code looks like this:

public virtual HttpWebRequest ToWebRequest() { var request = (HttpWebRequest) WebRequest.Create(description.Url); // .. snip setting request properties return request; } 

The function ToWebRequest() is called in several places, and from those places the Response is extracted and returned to even more methods. So its proving to be difficult to track it down. I did find this method that seems to show that the Response is being used but not disposed:

public override string ToString() { if (string.IsNullOrEmpty(ResponseBody)) { ResponseBody = ToWebResponse().ReadToEnd(); } return ResponseBody; } 
6
  • Try creating a system.net trace log for your application ( ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html ). It should show you why the SSL handshake is failing. Commented Aug 9, 2011 at 20:08
  • @feroze - thanks I got tracing working. But is is a massive log - is it possible to only log the connection attempt? the log is massive on my local dev box - it's going to be real bad on our live server with 1000's of users. Commented Aug 10, 2011 at 2:08
  • How big is the file? Can you just grep through it for the SSL handshake failure? Commented Aug 11, 2011 at 20:53
  • 1,000's of users each making hundreds of requests an hour. Its a big file. But yes I did just search for the failure, and found the cause of the error: stackoverflow.com/questions/6232746/… and I've put a fix in place, now just waiting to see if it fails again. Commented Aug 11, 2011 at 22:05
  • Was this problem ever resolved? - I have a similar problem connecting to Twitter from Amazon EC2 instances. Commented Jul 10, 2014 at 7:35

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.