1

I'm having this error... I'm using ASP.NET Core with the last version of driver C#.

The wait queue for acquiring a connection to server [server:port] is full.

Failed Method:

MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection

Call Stack:

MongoDB.Driver.MongoWaitQueueFullException
MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+AcquireConnectionHelper.CheckingOutConnection
MongoDB.Driver.Core.ConnectionPools.ExclusiveConnectionPool+<AcquireConnectionAsync>d__35.MoveNext
[external code]
MongoDB.Driver.Core.Servers.ClusterableServer+<GetChannelAsync>d__40.MoveNext
[external code]
MongoDB.Driver.Core.Operations.FindOperation`1+<ExecuteAsync>d__107.MoveNext
[external code]
MongoDB.Driver.OperationExecutor+<ExecuteReadOperationAsync>d__1`1.MoveNext
[external code]
MongoDB.Driver.MongoCollectionImpl`1+<ExecuteReadOperationAsync>d__59`1.MoveNext
[external code]
MongoDB.Driver.IAsyncCursorSourceExtensions+<FirstOrDefaultAsync>d__5`1.MoveNext
[external code]
Microsoft.ApplicationInsights.AspNet.ExceptionTrackingMiddleware+<Invoke>d__4.MoveNext

I have a Singleton DB Context.

Example API Controller:

[HttpPut]
        [Route("UpdatePosition")]
        public async Task<IActionResult> UpdatePosition([FromBody]AreaDto dto)
        {
            var idUser = User.GetUserId();

            if (dto == null)
                return HttpBadRequest("Fail request");

            _service.IdUser = idUser;


            var item = await _service.UpdateAreaPosition(dto);

            if (item == null)
                return HttpBadRequest("Fail request");

            return Ok(item);
        }

Service method:

public async Task<string> UpdateAreaPosition(AreaDto dto)
        {
            var area = await GetArea(dto);

            if (area == null || dto.Position?.PositionLeft == null || dto.Position.PositionTop == null) return null;

            area.Position.PositionLeft = dto.Position.PositionLeft;
            area.Position.PositionTop = dto.Position.PositionTop;
            await _repositoryAreas.Update(area);
            return area.Id;
        }

The GetArea and Update method are from a Repository Pattern:

Update method:

public virtual async Task<T> Update(T entity)
    {
        await _collection.ReplaceOneAsync(x => entity.Id.Equals(x.Id), entity, new UpdateOptions { IsUpsert = true });
        return entity;
    }

Get Area Method:

 private async Task<Area> GetArea(AreaDto dto)
        {
            var area = await _repositoryAreas.FirstOrDefaultAsync(t => t.Id == dto.Id);

            if (area == null)
                return null;


            return area;

        }

I have many other methods using mongoDB, but this is an example...

Instance class IMongoDatabse:

private static IMongoDatabase GetDatabaseFromUrl(MongoUrl url)
        {
            var client = new MongoClient(url);
            return client.GetDatabase(url.DatabaseName); // WriteConcern defaulted to Acknowledged
        }

Any ideas?

Community
  • 1
  • 1
chemitaxis
  • 13,889
  • 17
  • 74
  • 125
  • Please post a verifiable example. See http://stackoverflow.com/help/mcve – Saleem May 10 '16 at 10:24
  • @Saleem I have updated the question... thanks – chemitaxis May 10 '16 at 12:23
  • .net Core is not 100% compatible with full framework and I'm not sure if MongoDB driver is optimized for it yet. However I'll dig into it and post my finding. – Saleem May 10 '16 at 12:33
  • Thanks @Saleem In the official documentation says that Mongo C# Driver works fine with .NET Core... I have found that: http://blog.mlab.com/2013/11/deep-dive-into-connection-pooling/ – chemitaxis May 10 '16 at 12:38
  • I believe it's not fully supported yet. See jira. https://jira.mongodb.org/plugins/servlet/mobile#issue/CSHARP-1177 – Saleem May 10 '16 at 12:40
  • Maybe, I think the error could be in how I have created the DI of Repository: services.AddScoped, MongoRepository>(); Do I need to change it to AddSingleton? Thanks @Saleem – chemitaxis May 10 '16 at 12:45
  • 1
    @Saleem One datail, I use full dnx 451, that supports MongoDb C# Driver – chemitaxis May 11 '16 at 21:07
  • 1
    See thread at https://groups.google.com/forum/#!msg/mongodb-csharp/gkhOrhISuPA/3czqyDnBdW4J – Saleem May 12 '16 at 12:46
  • @Saleem Thanks!! I have added this param to my connection string: &waitQueueMultiple=10000, do you think it solve my problem? Thanks again!! – chemitaxis May 12 '16 at 13:00

0 Answers0