Why C#.NET Query gives "Fatal" status most of the time?

Hello All,

I am new in Couchbase and want to execute a Group By query on database. I have created an MVC application using C#.NET. Below is the code snippet:

> var config = new ClientConfiguration
> {
>     Servers = new List<Uri>
>   {
>        new Uri("http://172.18.109.151:8091/pools"),
>        new Uri("http://172.18.109.81:8091/pools"),
>        new Uri("http://172.18.109.46:8091/pools"),
>        new Uri("http://172.18.109.60:8091/pools"),
>        new Uri("http://172.18.109.80:8091/pools")
>   },
>     UseSsl = false,
>     DefaultOperationLifespan = 8100000,
>     BucketConfigs = new Dictionary<string, BucketConfiguration>
>                   {
>                     {"NLA-testing", new BucketConfiguration
>                     {
>                       BucketName = "NLA-testing",
>                       UseSsl = false,
>                       Password = "",
>                       DefaultOperationLifespan = uint.MaxValue,
>                       PoolConfiguration = new PoolConfiguration
>                       {
>                         MaxSize = 10,
>                         MinSize = 5,
>                         SendTimeout = int.MaxValue, // this value wa
>                       }
>                     }}}
> };

> using (Cluster cls = new Cluster(config))
> {
>     using (var buc = cls.OpenBucket("NLA-testing"))
>     {
>         string AggQuery = "SELECT Status.StatusCode, Status.Detail, Status.Meaning, COUNT(*) AS count FROM `NLA-testing` where  (Status.StatusCode is not missing and Status.Detail is not missing and Status.Meaning is not missing)GROUP BY Status.StatusCode, Status.Detail, Status.Meaning";
>         var AggResult = buc.Query<dynamic>(AggQuery);
>         foreach (var row in AggResult.Rows)
>         {
>             if (row["StatusCode"] != null)
>                 datalist.Add(new StatusCount(Convert.ToInt32(row["StatusCode"]), Convert.ToInt32(row["count"]), row["Meaning"].ToString(), row["Detail"].ToString()));
>         }
>     }
> }

Below line creates error. “QueryResult.Status” gives “Fatal” and Exception gives “Unexpected character encountered while parsing value: <. Path , line 0, position 0.” message.

var AggResult = buc.Query(AggQuery);

More information is shown in below image:

I don’t know why it is happening. Is my configurations missing anything OR I am using wrong way to execute a query? If I run the code for multiple times then “QueryResult.Status” gives “Success” once in 10 runs.

Can anyone please help me to solve it out?

Thanks
Chetan

@GhodasaraC

I’m wondering if the problem is with the query server itself. My first guess is that you’re getting HTML back instead of JSON, based on the error that there is a “<” character in the first position of the response. A few quick thoughts

  1. Is there any kind of proxy/firewall between this app and the server running the Query service? Note that this service runs on port 8093.
  2. Have you tried using cbq to run queries from the command line to see if that works?
  3. What version of couchbase server and the .Net client are you using?

Brant

1 Like

@btburnett3

Thank you for your quich reply. :slight_smile:

Here is the description on all machines in cluster.

1. Is there any kind of proxy/firewall between this app and the server running the Query service? Note that this service runs on port 8093.

Yes, the LAN contains Proxy for connecting to internet. Further, in the application I’m using google charts, which requires internet for downloading scripts run time.
Windows Firewall is OFF on PC1 (from above list).

If I keep trying to execute query using below code, then it gives “QueryStatus.Success” once in 10 times (randomly). If proxy/firewall is the problem then I guess this should not be happened.

using (Cluster cls = new Cluster(config))
{
	using (var buc = cls.OpenBucket("NLA-testing"))
	{
		string AggQuery = "SELECT Status.StatusCode, Status.Detail, Status.Meaning, COUNT(*) AS count FROM `NLA-testing` where  (Status.StatusCode is not missing and Status.Detail is not missing and Status.Meaning is not missing)GROUP BY Status.StatusCode, Status.Detail, Status.Meaning";
		IQueryResult<dynamic> AggResult = null;
		int count = 0;
		do
		{
			count++;
			AggResult = buc.Query<dynamic>(AggQuery);
			foreach (var row in AggResult.Rows)
			{
				if (row["StatusCode"] != null)
					datalist.Add(new StatusCount(Convert.ToInt32(row["StatusCode"]), Convert.ToInt32(row["count"]), row["Meaning"].ToString(), row["Detail"].ToString()));
			}
		} while (AggResult.Status != QueryStatus.Success);
	}
}

2. Have you tried using cbq to run queries from the command line to see if that works?

Yes, the same query runs perfectly from cbq command line. (From all machines)

3. What version of couchbase server and the .Net client are you using?

Couchbase Server : 4.5.0-2203 Enterprise Edition (build-2203)
Couchbase.NetClient : 2.2.7.0 (Runtime version : v4.0.30319)

Thanks
Chetan

@GhodasaraC -

Can you use fiddler to sniff the requests going back and forth between the client? As @btburnett3 suggested, the Exception message indicates that the client is treating HTML as JSON - the HTML will give you the HTTP error that occurred. This wil help to diagnose the issue.

On a side note, the client should handle the HTML response correctly, but it doesn’t appear to be the case (from what I can see).

-Jeff

@jmorris @btburnett3
Thanks for suggesting Fiddler from where I found below.

I have listed 5 IP addresses in Servers list (in ClientConfiguration). Hence, when
var AggResult = buc.Query(AggQuery);
statement executes, it makes a request to a query service on any of above 5 list using
http://172.18.109.XXX:8093/query (here XXX is any of 151,81,46,60,80)

I guess, here proxy creates a problem. The application is running from 172.18.109.151 only, which is having proxy settings. And when this machine makes above query service request, it gives error “Invalid Request” [HTTP/1.0 417 Expectation Failed whose content type is “text/html”]. Before executing above statement, if i remove proxy settings then every time query returns perfect result. But, I have to give proxy in order to connect internet for running the application.

Can you please tell me any solution, if my observation looks proper?

Thanks
Chetan

@GhodasaraC

It sounds like a problem with the proxy itself. Is there some way to bypass the proxy for local LAN traffic?

Brant

Now I use Firefox instead of Chrome. Firefox applies proxy only on browser not on the system. Hence, my application will run with proxy (with internet) and the cluster can communicate without proxy also.

It’s working now. Thanking you for the help. :slight_smile:

-Chetan

1 Like

Couchbase is configured use http 80 port to query views and the proxy responds with an authentication error.
To solve this you need to configure .NET not to use default proxy in this case. This is done in the relevant config files:

Added the following to my Projects App.config has resolved the issue for me:

  <system.net>
    <defaultProxy>
      <proxy usesystemdefault="False" />
    </defaultProxy>
  </system.net>
1 Like