[JAVA-1886] MongoClient.islocked() method fails Created: 13/Jul/15  Updated: 15/Oct/15  Resolved: 15/Jul/15

Status: Closed
Project: Java Driver
Component/s: Command Operations
Affects Version/s: 3.0.0
Fix Version/s: 3.0.3, 3.1.0

Type: Bug Priority: Minor - P4
Reporter: Dharshan Rangegowda Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I am trying to unlock a locked 3.x database.

public static void unlockMongoDB(MongoClient m) throws Exception
    {
        String context = "MongoDBHelper-unlockMongoDB: ";
        Logger.info(context + "Checking if MongoDB instance needs to be unlocked");
 
        if(m.isLocked())
        {
            Logger.info(context + "Unlocking MongoDB instance");
            m.unlock();               
        }
    }

isLocked() fails with the following stack trace

13 Jul 2015 02:20:20,893 ERROR ~ Prematurely reached end of stream
13 Jul 2015 02:20:20,894 ERROR ~ com.mongodb.MongoSocketReadException: Prematurely reached end of stream
        at com.mongodb.connection.SocketStream.read(SocketStream.java:88)
        at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:491)
        at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:221)
        at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:102)
        at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:416)
        at com.mongodb.connection.QueryProtocol.receiveMessage(QueryProtocol.java:282)
        at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:229)
        at com.mongodb.connection.QueryProtocol.execute(QueryProtocol.java:38)
        at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:155)
        at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:219)
        at com.mongodb.connection.DefaultServerConnection.query(DefaultServerConnection.java:166)
        at com.mongodb.operation.FindOperation$1.call(FindOperation.java:397)
        at com.mongodb.operation.FindOperation$1.call(FindOperation.java:394)
        at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:195)
        at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:168)
        at com.mongodb.operation.FindOperation.execute(FindOperation.java:394)
        at com.mongodb.operation.FindOperation.execute(FindOperation.java:57)
        at com.mongodb.Mongo.execute(Mongo.java:738)
        at com.mongodb.Mongo$2.execute(Mongo.java:725)
        at com.mongodb.DBCollection.findOne(DBCollection.java:737)
        at com.mongodb.DBCollection.findOne(DBCollection.java:710)
        at com.mongodb.DBCollection.findOne(DBCollection.java:657)
        at com.mongodb.DBCollection.findOne(DBCollection.java:646)
        at com.mongodb.Mongo.isLocked(Mongo.java:574)

Also I have noticed that if I pass the MongoClient object to another function and unlock it, the unlock appears to hang. If I use a try {} finally {} and unlock, it appears to go through.



 Comments   
Comment by Jeffrey Yemin [ 16/Jul/15 ]

Fix is now available in the 3.0.3 release.

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Ignoring MongoClient.isLocked test for sharded clusters.

JAVA-1886
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/5f7ab595c012b2e4c6c8a2ee234f71df2c068273

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Ignoring MongoClient.isLocked test for sharded clusters.

JAVA-1886
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/dfe49db1557b0cd0ac6e2792bda63a5ff3c06147

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Changed FindOperation to only use the $query meta-operator if there other meta-operators that are being used.
This is necessary to make the check for whether the server is fsync-locked work, as that particular usage of OP_QUERY
does not handle the $query meta-operator and simply closed the connection.

JAVA-1886
Branch: 3.0.x
https://github.com/mongodb/mongo-java-driver/commit/44200b1f5f1dab08770cc461b66294ad314fbe07

Comment by Githook User [ 15/Jul/15 ]

Author:

{u'username': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}

Message: Changed FindOperation to only use the $query meta-operator if there other meta-operators that are being used.
This is necessary to make the check for whether the server is fsync-locked work, as that particular usage of OP_QUERY
does not handle the $query meta-operator and simply closed the connection.

JAVA-1886
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/b7ffd2ca7e07f42b3cc8ad9114218bf351b28b42

Comment by Jeffrey Yemin [ 15/Jul/15 ]

Never mind, I was able to reproduce this.

Comment by Jeffrey Yemin [ 14/Jul/15 ]

Is the MongoClient connecting to a standalone, a replica set, or a mongos router?

Also, please paste a code snippet for how you create and initialize the MongoClient instance.

Regards,
Jeff

Generated at Thu Feb 08 08:55:46 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.