Bug setting timeout in the RestSharpHttpClient in v1.2.1 .NET client

We are using Couchbase views and have discovered a very aggressive timeout when the underlying web request executes in v1.2.1 of the .NET SDK:

----> System.Net.WebException : The request was aborted: The operation has timed out.

–WebException
at Couchbase.RestSharpHttpClient.RestSharpResponseWrapper.ExecuteWith(RestClient client)
at Couchbase.RestSharpHttpClient.RestSharpRequestWrapper.Couchbase.IHttpRequest.GetResponse()
at Couchbase.CouchbaseViewHandler.GetResponse(IDictionary2 viewParams) at Couchbase.CouchbaseViewHandler.<transformresults>d__01.MoveNext()

This timeout happens almost immediately, which was suspect. We’re using the CouchbaseClientConfiguration class to configure the Couchbase client. A quick check revealed that the default timeout is set as follows:

public class CouchbaseClientConfiguration : ICouchbaseClientConfiguration
{
private Type nodeLocator;
private ITranscoder transcoder;
private IMemcachedKeyTransformer keyTransformer;
private TimeSpan defaultHttpRequestTimeout = TimeSpan.FromMinutes(1);

This then gets consumed here:

public RestSharpHttpClient(Uri baseUri, string username, string password, TimeSpan timeout, bool shouldInitConnection)
{
client = new RestClient { BaseUrl = baseUri.ToString() };
client.Timeout = timeout.Milliseconds;
if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password))
{
client.Authenticator = new HttpBasicAuthenticator(username, password);
}

The offending code is client.Timeout = timeout.Milliseconds; which should be client.Timeout = timeout.TotalMilliseconds;, otherwise one gets the millisecond portion, which will be 0. Even worse, you can partially work around it, but you can only set the timeout to at most 999ms, which, I’ll grant, will be slow for a LAN. When using an App.config and the appropriate configuration section, this seems to be set correctly, but we’re using a centralised configuration system and not the App.config.

Thanks for bringing this bug to my attention, and for your detailed analysis. I’ve opened a ticket at http://www.couchbase.com/issues/browse/NCBC-239. I’ve submitted the patch and the fix will be part of the 1.2.4 release the first week of April. A verification build is attached to the ticket. Apologies for the inconvenience…