com.mongodb.MongoTimeoutException: Timed out after 30000 ms while wai ting for a server that matches ReadPreferenceServerSelector{readPreference=prima ry}. Client view of cluster state is {type=UNKNOWN, servers=[{address=locahost:2 7017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketExceptio n: locahost}, *caused by* {java.net.UnknownHostException: locahost}}]

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • Error in Play-MongoDB.
    via by Tam Truong,
  • I have a testing setup where I SSH tunnel from my local machine to a machine in a different VPC that hosts a mongo hidden secondary. It seems to be impossible to read from that secondary without given the driver access to the primary as well. I get the following exception when I try: {{ feature-dev 20:00:43.216 INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27018, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 2]}, minWireVersion=0, maxWireVersion=3, maxDocumentSize=16777216, roundTripTimeNanos=10440806} feature-dev 20:00:43.224 INFO org.mongodb.driver.cluster - Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=REPLICA_SET_SECONDARY, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 4]}, minWireVersion=0, maxWireVersion=3, maxDocumentSize=16777216, roundTripTimeNanos=9489844, setName='mongo1', hosts=[10.0.0.126:27017, 10.0.0.124:27017, 10.0.0.125:27017], passives=[], arbiters=[], primary='10.0.0.124:27017', tagSet=TagSet{[]}} feature-dev[ERROR] com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches PrimaryServerSelector. Client view of cluster state is {type=REPLICA_SET, servers=[{address=localhost:27017, type=REPLICA_SET_SECONDARY, roundTripTime=10.6 ms, state=CONNECTED}] feature-dev[ERROR] at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:370) feature-dev[ERROR] at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:101) feature-dev[ERROR] at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75) feature-dev[ERROR] at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71) feature-dev[ERROR] at com.mongodb.binding.ClusterBinding.getWriteConnectionSource(ClusterBinding.java:68) feature-dev[ERROR] at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:104) feature-dev[ERROR] at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:97) feature-dev[ERROR] at com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol(CommandOperationHelper.java:85) feature-dev[ERROR] at com.mongodb.operation.CommandWriteOperation.execute(CommandWriteOperation.java:55) feature-dev[ERROR] at com.mongodb.Mongo.execute(Mongo.java:745) feature-dev[ERROR] at com.mongodb.Mongo$2.execute(Mongo.java:728) feature-dev[ERROR] at com.mongodb.DB.executeCommand(DB.java:583) feature-dev[ERROR] at com.mongodb.DBCollection.getStats(DBCollection.java:1858) feature-dev[ERROR] at com.mongodb.hadoop.splitter.MongoSplitterFactory.getSplitterByStats(MongoSplitterFactory.java:73) feature-dev[ERROR] at com.mongodb.hadoop.splitter.MongoSplitterFactory.getSplitter(MongoSplitterFactory.java:113) ... }} (can send full stack trace if necessary. Unable to attach it) I'm able to read from the primary fine. Is this behaviour unavoidable? Can the driver not function without being able to query the primary for some reason? Do I need a testing setup that has access to both primary and hidden secondary?
    via by Ratan Sebastian,
    • com.mongodb.MongoTimeoutException: Timed out after 30000 ms while wai ting for a server that matches ReadPreferenceServerSelector{readPreference=prima ry}. Client view of cluster state is {type=UNKNOWN, servers=[{address=locahost:2 7017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketExceptio n: locahost}, *caused by* {java.net.UnknownHostException: locahost}}] at com.mongodb.connection.BaseCluster.createTimeoutException(BaseCluster.java:377) at com.mongodb.connection.BaseCluster.selectServer(BaseCluster.java:104) at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:75) at com.mongodb.binding.ClusterBinding$ClusterBindingConnectionSource.<init>(ClusterBinding.java:71) at com.mongodb.binding.ClusterBinding.getReadConnectionSource(ClusterBinding.java:63) at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:402) at com.mongodb.operation.FindOperation.execute(FindOperation.java:510) at com.mongodb.operation.FindOperation.execute(FindOperation.java:81) at com.mongodb.Mongo.execute(Mongo.java:836) at com.mongodb.Mongo$2.execute(Mongo.java:823)

    Users with the same issue

    Unknown visitor1 times, last one,
    rsprangemeijer
    rsprangemeijer2 times, last one,
    rocday
    rocday1 times, last one,
    pulse00
    pulse001 times, last one,
    Dunmer
    Dunmer1 times, last one,
    16 more bugmates