The wait queue for acquiring a connection to server ******* is full. [MongoDB]

一笑奈何 提交于 2019-12-24 17:49:56

问题


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?

来源:https://stackoverflow.com/questions/37135302/the-wait-queue-for-acquiring-a-connection-to-server-is-full-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!