[JAVA-1870] Waiting for 30000 ms before timing out Created: 23/Jun/15  Updated: 04/Aug/20  Resolved: 23/Jun/15

Status: Closed
Project: Java Driver
Component/s: API
Affects Version/s: 3.1.0
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Jinho Choi Assignee: Unassigned
Resolution: Done Votes: 0
Labels: driver, timeout
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mongodb 3.0.3, jdk 1.6, Centos 3,
Only one MongoDB server (14.0.xx.xxx, 27017)



 Description   

There is an timeout message to update a document on my mongodb.
What is wrong ?

Here is log message :

INFO: No server chosen by PrimaryServerSelector from cluster description ClusterDescription{
  type=UNKNOWN, connectionMode=SINGLE, 
  all=[ServerDescription{address=14.0.xx.xxx:27017, type=UNKNOWN, state=CONNECTING}]}. 
 Waiting for 30000 ms before timing out

Below is java code:

MongoClient mongoClient = new MongoClient("14.0.xx.xxx", 27017);
MongoDatabase db = client.getDatabase("axis");
 
String axisDate = axis.substring(0, 10);
int axisHour = Integer.parseInt(axis_hour);
		
String id = axisDate + "_" + gid + "_" + cname + "_" + axisHour;
		
Document key = new Document("_id", id); 
Document value = new Document("$set", new Document("_id", id)
     .append("gid", gid)
     .append("service_name", cname)  										    
     .append("axis", axisDate)
     .append("axis_hour", axisHour)
     .append("bandwidth", bandwidth)
     .append("peak", peak));
		
UpdateOptions uo = new UpdateOptions();
try {
     UpdateResult rs =      
     db.getCollection("video_cdn_traffic_log").updateOne(key, value, uo.upsert(true));
}catch (MongoWriteException e) {
   e.printStackTrace();
}catch (MongoWriteConcernException e) {
  e.printStackTrace();
}catch (MongoException e) {
  e.printStackTrace();
}finally{
  client.close();			
}



 Comments   
Comment by Ross Lawley [ 23/Jun/15 ]

Hi arsis

It's the log message you get when the driver isn't able to select a server to speak to. Waiting for 30000 ms before timing out is because of the ServerSelectorTimeout:

The server selection timeout in milliseconds, defines how long the driver will wait for server selection to succeed before throwing an exception.

The default is 30,000ms and if it can't connect to the server after that time it will then throw an exception. This can be configured via MongoClientOption.Builder.

As you are running a single server, the questions to ask are was the MongoDB server up and running and can it be connected to from where the code is being run?

Just to let you know this project is for Java driver bugs or feature requests. The best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailing list or stackoverflow as you will reach a boarder audience there. If your business requires an answer from MongoDB within a set time frame then we do offer production support.

As the server selection message is the expected behaviour of the driver, I'm closing this as works as designed. If you do post to the mailing list or stackoverflow please post a link on this ticket and I will endeavour to follow up there.

All the best,

Ross

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