Spring Boot app reports "Too many operations are already waiting for a connection" when accessing MongoDB
search cancel

Spring Boot app reports "Too many operations are already waiting for a connection" when accessing MongoDB

book

Article ID: 297137

calendar_today

Updated On:

Products

Support Only for Spring

Issue/Introduction

A Spring Boot app reports the error message "Too many operations are already waiting for a connection" when accessing the MongoDB. The error messages look similar to the following:
Calling onError threw an exception
reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.data.mongodb.UncategorizedMongoDbException: Too many operations are already waiting for a connection. Max number of operations (maxWaitQueueSize) of 500 has been exceeded.; nested exception is com.mongodb.MongoWaitQueueFullException: Too many operations are already waiting for a connection. Max number of operations (maxWaitQueueSize) of 500 has been exceeded.
Caused by: org.springframework.data.mongodb.UncategorizedMongoDbException: Too many operations are already waiting for a connection. Max number of operations (maxWaitQueueSize) of 500 has been exceeded.; nested exception is com.mongodb.MongoWaitQueueFullException: Too many operations are already waiting for a connection. Max number of operations (maxWaitQueueSize) of 500 has been exceeded.
	at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:138)
	at org.springframework.data.mongodb.core.ReactiveMongoTemplate.potentiallyConvertRuntimeException(ReactiveMongoTemplate.java:2777)




Resolution

The maxPoolSize defines the maximum number of connections in the connection pool. The default value is 100, which might be too small. 

For example, you can scale up the maxPoolSize to 300 and directly add it in the connection string URI.
String mongoURI=  "mongodb://user:password@localhost:27017/kafka?authSource=admin?maxPoolSize=300";