Hi All,
I’ve encountered a problem of connection from my docker .net core 3.1 web.api against CB Server running on a virtual machine in the lan. The problem is related just to the scenario in which the web.api is running in a docker container. In the following scenarios the system works properly:
- web.api in IIS Express on my laptop
- IIS on a server
- CB server in the same docker client of the web.api
I’m using .net SDK 2.7. The bootstrap is the following:
// define settings for this Couchbase Cluster connection
var config = new ClientConfiguration()
{
LoggerFactory = loggerFactory,
PoolConfiguration = new PoolConfiguration
{
MaxSize = 20,
MinSize = 1,
SendTimeout = 12000
},
// Impostazione del keep-alive per verifica se migliora la connettività al cluster
// https://blog.couchbase.com/introducing-couchbase-.net-sdk-2.1.0-the-asynchronous-couchbase-.net-client/
EnableTcpKeepAlives = true, //default it true
TcpKeepAliveTime = 1000 * 60, //set to 60secs
TcpKeepAliveInterval = 5000,
// assign one or more Couchbase Server URIs available for bootstrap
Servers = new List<Uri> {
new Uri(server)
},
UseSsl = false,
BucketConfigs = new Dictionary<string, BucketConfiguration>
{
//{"SmartPipeTracking", new BucketConfiguration
{bucketName, new BucketConfiguration
{
UseEnhancedDurability = true,
BucketName = bucketName,
UseSsl = false
}
},
}
};
// Eseguo lo shoutdown qualora il metodo di inizializzazione venisse richiamato due volte
if(ClusterHelper.Initialized) Cleanup();
// initialize Cluster, to be built as a singleton
ClusterHelper.Initialize(config, new PasswordAuthenticator(username, password));
I’ve also tried to set the following tcp parameter inside the container:
sysctls:
- net.ipv4.tcp_keepalive_time=295
- net.ipv4.tcp_keepalive_intvl=45
- net.ipv4.tcp_keepalive_probes=15
privileged: true
and I confirm that accessing the container shell the values are correct.
The problem is logged as this:
2020-12-04 12:56:20.0757 | DEBUG | init main
2020-12-04 13:04:36.2436 | ERROR | System.IO.IOException: The response ended prematurely.
at System.Net.Http.HttpConnection.FillAsync()
at System.Net.Http.HttpConnection.ChunkedEncodingReadStream.ReadAsyncCore(Memory`1 buffer, CancellationToken cancellationToken)
at System.IO.StreamReader.ReadBufferAsync(CancellationToken cancellationToken)
at System.IO.StreamReader.ReadLineAsyncInternal()
2020-12-04 13:04:48.4162 | ERROR | Failed to perform SelectBucket operation for ‘SmartPipeTracking’. Reason TransportFailure.
It happens after more or less 10 min the web.api startup. After that the communication with the database is not working anymore.
The containers are running in a dedicated bridge network.