I’m experiencing an issue where any QueryAsync call through the .NET SDK results in the following thrown exception ONLY when the application is in a docker container. The same code run on Kestrel does not have this issue (with Couchbase still in a docker container).
[Error] System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.Http.CurlException: Couldn't connect to server
at System.Net.Http.CurlHandler.ThrowIfCURLEError(CURLcode error)
at System.Net.Http.CurlHandler.MultiAgent.FinishRequest(StrongToWeakReference`1 easyWrapper, CURLcode messageResult)
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at System.Net.Http.HttpClient.<FinishSendAsync>d__58.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Couchbase.N1QL.QueryClient.<ExecuteQueryAsync>d__19`1.MoveNext()
Here’s a minimal sample program I’ve written that proves that it CAN connect to the server because I am able to get back a document using GetDocumentAsync.
Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using Couchbase;
using Couchbase.Configuration.Client;
using Couchbase.Management.Indexes;
namespace ConsoleApp1
{
class Program
{
private static readonly Cluster Cluster = new Cluster(new ClientConfiguration()
{
Servers = new List<Uri>
{
new Uri("http://couchbase-server1:8091/pools")
}
});
private static void Main(string[] args)
{
using (var bucket = Cluster.OpenBucket("default"))
{
var isOpen = Cluster.IsOpen("default") ? "open" : "closed";
Console.WriteLine($"Cluster is {isOpen}.");
var doc = new Document<MyModel>
{
Content = new MyModel
{
_service = "example",
_type = "myModel",
Name = "Name",
DisplayName = "Display name"
},
Id = "exampleId"
};
bucket.UpsertAsync<MyModel>(doc);
var result = bucket.GetDocumentAsync<MyModel>(doc.Id).Result;
Console.WriteLine(
result.Success
? $"Succesfully got back document with id '{result.Id}'"
: $"Failed to get document with id '{doc.Id}': Exception: {result.Exception?.Message} --- INNER --- {result.Exception?.InnerException?.Message}");
const string indexName = "Idx_Example";
var indexDropResult = bucket.QueryAsync<IndexInfo>($"DROP INDEX `{bucket.Name}`.`{indexName}`").Result;
Console.WriteLine(
!indexDropResult.Success ? $"Failed to drop index {indexName}: Error count: {indexDropResult.Errors.Count}: Exception: {indexDropResult.Exception?.Message} --- INNER --- {indexDropResult.Exception?.InnerException?.Message}"
: $"Succesfully dropped index {indexName}");
// Wait for index to drop
System.Threading.Thread.Sleep(2000);
var indexResult = bucket.QueryAsync<IndexInfo>($"CREATE INDEX `{indexName}` ON `{bucket.Name}`(`name`) WHERE (`_service`='example' AND `_type` = 'myModel')").Result;
Console.WriteLine(
!indexResult.Success ? $"Failed to create index {indexName}: Error count: {indexResult.Errors.Count}: Exception: {indexResult.Exception?.Message} --- INNER --- {indexResult.Exception?.InnerException?.Message}"
: $"Successfully created index {indexName}");
// Wait for index to build
System.Threading.Thread.Sleep(5000);
var queryResult = bucket.QueryAsync<MyModel>($"SELECT `{bucket.Name}`.* FROM `{bucket.Name}` WHERE `name`='Name' AND `_service`='example' AND `_type`='myModel'").Result;
Console.WriteLine(
!queryResult.Success
? $"Failed to execute query : Error count: {indexDropResult.Errors.Count}: Exception: {indexDropResult.Exception?.Message} --- INNER --- {indexDropResult.Exception?.InnerException?.Message}"
: $"Result found: {queryResult.Rows.FirstOrDefault().DisplayName}");
}
}
}
}
MyModel.cs
namespace ConsoleApp1
{
public class MyModel
{
public string Name { get; set; }
public string DisplayName { get; set; }
public string _type { get; set; }
public string _service { get; set; }
}
}
Result of this application when run in Kestrel:
Cluster is open.
Succesfully got back document with id 'exampleId’
Succesfully dropped index Idx_Example
Successfully created index Idx_Example
Result found: Display name
Result when run in docker:
Cluster is open.
Succesfully got back document with id 'exampleId’
Failed to drop index Idx_Example: Error count: 0: Exception: An error occurred while sending the request. — INNER — Couldn’t connect to server
Failed to create index Idx_Example: Error count: 0: Exception: An error occurred while sending the request. — INNER — Couldn’t connect to server
Failed to execute query : Error count: 0: Exception: An error occurred while sending the request. — INNER — Couldn’t connect to server