Handle timeouts in sync execute code

2,915 views
Skip to first unread message

Jason Famularo

unread,
Mar 5, 2012, 5:37:48 PM3/5/12
to rest...@googlegroups.com
I am attempting to use RestSharp to handle simple GET calls to a web service (I control) from a Windows service (I also control). I am forcing the web service to timeout (by not responding by the timeout set on the request object), to see how it handles that scenario.

I expected it to set the response.ResponseStatus to TimedOut, but it set it to Error. Looking at the source, all WebExceptions are caught (within the Execute method in  RestClient.Sync.cs) and the ResponseStatus is set to Error. Should/Could this be TimedOut? A WebException could be inspected to determine if it was a timeout.

Compare to the Async code, which has three references to ResponseStatus.TimedOut.

So my question is, should the sync code have a concept of timeout? Or is the concept of timeout in Async something different I'm not catching onto?

Andrew Young

unread,
Mar 6, 2012, 1:29:02 PM3/6/12
to rest...@googlegroups.com
The sync methods take advantage of the default behavior for HttpWebRequest.Timeout. Async timeouts are handled by RestSharp. If timeout isn't working for sync, that could be a bug. Can you send code as a simple test case?

Jason Famularo

unread,
Mar 6, 2012, 1:32:58 PM3/6/12
to rest...@googlegroups.com
Sure, where should I sent the sample too?


On Tuesday, March 6, 2012 1:29:02 PM UTC-5, ayoung wrote:
The sync methods take advantage of the default behavior for HttpWebRequest.Timeout. Async timeouts are handled by RestSharp. If timeout isn't working for sync, that could be a bug. Can you send code as a simple test case?

John Sheehan

unread,
Mar 6, 2012, 11:25:56 PM3/6/12
to rest...@googlegroups.com
Right here. Just remove any sensitive data.

Jason Famularo

unread,
Mar 7, 2012, 7:15:37 PM3/7/12
to rest...@googlegroups.com
Here is my simple test case:

var client = new RestClient(baseUrl)
{
    Timeout = someTimeoutInMilliseconds
};

var request = new RestRequest(url)
{
    Method = Method.GET,
    Timeout = someTimeoutInMilliseconds
};

// Call a url that takes more than someTimeoutInMilliseconds to respond.
var response = client.Execute(request);

// response.ResponseStatus == ResponseStatus.Error here, not ResponseStatus.TimedOut

I would expect a status of timed out, not error. The native .NET object knows it timed out, it's just not getting set as such in RestSharp.

As a bonus, I'd be willing to submit a simple pull request to change this behavior. ;)

Rand Clark

unread,
Oct 15, 2015, 8:07:36 PM10/15/15
to RestSharp
Has there ever been a resolution to this issue?  I am still seeing this behavior in RestSharp.Net2.dll, ver=102.7.0.0.  Thank you.
Message has been deleted

Matias Heffel

unread,
Dec 18, 2015, 10:14:14 AM12/18/15
to RestSharp

Here there is another example and the same is happening to us:

// Set up the client
var client = new RestClient(endpointUrl);
client.Timeout = 3 * 1000;

var req = new RestRequest(string.Empty);
var result = client.Post(req);

and the result it's the same, it tokes more than 3 seconds and the ResponseStatus is Error
also we tried with 
req.Timeout = 5 * 1000;
and happened the same

Thanks for your response

Reply all
Reply to author
Forward
0 new messages