user3419766
user3419766

Reputation: 73

A driver operation has been interrupted (mongodb exception)

I am using mongo database for my application for connection spooling in configured the below mongoOption while creating connection

MongoOptions options = new MongoOptions();
   options.autoConnectRetry = true;
   options.connectionsPerHost = 40;
   options.threadsAllowedToBlockForConnectionMultiplier = 25;

while exceuting my application,getting the following exception

com.mongodb.MongoInterruptedException: A driver operation has been interrupted
at com.mongodb.DBPortPool.get(DBPortPool.java:216)
at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:440)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:177)
at com.mongodb.DBTCPConnector.say(DBTCPConnector.java:155)
at com.mongodb.DBApiLayer$MyCollection.update(DBApiLayer.java:349)
at com.mongodb.DBCollection.update(DBCollection.java:177)
at com.mongodb.DBCollection.save(DBCollection.java:817)
at com.mongodb.DBCollection.save(DBCollection.java:785)
at cherrypick.ck.datalayer.mongo.MongoDataAccessLayer.saveObject(MongoDataAccessLayer.java:361)
at cherrypick.ck.emailinterface.CKMailMonitor.processIncomingMessage(CKMailMonitor.java:170)
at cherrypick.ck.emailinterface.CKMailMonitor.monitorNewMessages(CKMailMonitor.java:253)
at cherrypick.ck.emailinterface.CKMailMonitor.run(CKMailMonitor.java:275)
Caused by: java.lang.InterruptedException
at java.util.concurrent.locks.AbstractQueuedSynchronizer.tryAcquireSharedNanos(AbstractQueuedSynchronizer.java:1325)
at java.util.concurrent.Semaphore.tryAcquire(Semaphore.java:414)
at com.mongodb.util.SimplePool.permitAcquired(SimplePool.java:148)
at com.mongodb.util.SimplePool.get(SimplePool.java:110)
at com.mongodb.DBPortPool.get(DBPortPool.java:214)

could any one can help me to solve the issue.

Thanks in advance Raja Subramani

Upvotes: 7

Views: 9052

Answers (4)

Tyler MacMillan
Tyler MacMillan

Reputation: 592

This can occur when using a small connection pool and overloading it with so many requests that normal functionality cannot occur. For example, I had a connection pool with a max of 10 connections, and fired off 50 requests that would each take over 10 seconds, as well as threads that were checking other mongo collections for work.

Upvotes: 0

ClarkChen
ClarkChen

Reputation: 16

I met that problem before, it was caused by the mongo database not your code, so you can enlarge the socket-timeout in your config file or call the dba.

Upvotes: 0

hcarrasko
hcarrasko

Reputation: 2352

The same error appear when you open multiple mongodb instances. Be sure that are closing the mongo clients before open a new instance. For example:

MongoClient mongo = new MongoClient ("localhost", 27017);

be sure of do: mongo.close(); I hope it helps

Upvotes: 0

takirala
takirala

Reputation: 2019

I recently faced this exception. This happens if Thread is already interrupted and you are further trying to do some operation on same thread. I handled this exception by clearing the flag by using Thread.interrupted method of java.lang.Thread

Upvotes: 1

Related Questions