[JAVA-752] Make exception message say timeout if exception was caused by a socket timeout exception Created: 06/Feb/13  Updated: 31/Mar/15  Resolved: 25/Jun/13

Status: Closed
Project: Java Driver
Component/s: Monitoring
Affects Version/s: None
Fix Version/s: 3.0.0

Type: Improvement Priority: Major - P3
Reporter: John Feibusch Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

We got the exception below. I think it's caused by a socket timeout, but from the exception message below, it's apparently not possible to know for sure. I would like the MongoException message to be different if the IOException is a SocketTimeoutException. Something like "socket timeout trying to call something" rather than "can't call something".

Here is the exception. I am not asking for help troubleshooting this exception, I am including it as an example.

com.mongodb.MongoException$Network: can't call something : (host info removed)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:226)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:313)
at com.mongodb.DB.command(DB.java:174)
at com.mongodb.DB.command(DB.java:158)
at com.mongodb.DB.command(DB.java:198)
at com.mongodb.DBCollection.getCount(DBCollection.java:899)
at com.mongodb.DBCollection.getCount(DBCollection.java:870)
at com.mongodb.DBCollection.getCount(DBCollection.java:858)
at com.google.code.morphia.query.QueryImpl.countAll(QueryImpl.java:174)



 Comments   
Comment by Jeffrey Yemin [ 31/Mar/15 ]

Closing all resolved 3.0.0 issues, as 3.0.0 has been tagged and released.

Comment by Jeffrey Yemin [ 25/Jun/13 ]

In 3.0.x there is a specific exception subtype for timeouts. See

https://github.com/jyemin/mongo-java-driver/commit/d8d38a7

Comment by Jeffrey Yemin [ 08/Feb/13 ]

Hi John,

It's common practice to log chained exceptions this way. I think your best best is to increase the character/line count of your exception handler.

Comment by John Feibusch [ 07/Feb/13 ]

Unfortunately it looks like our exception handler, which logs this stack trace, only logs the first 600 characters or so. So the nested exception that you show doesn't appear in our logs.

Comment by Scott Hernandez (Inactive) [ 06/Feb/13 ]

Can you include the full exception stack you are getting, included the nested ones?

In the case of an IOException (like SocketTimeoutException) as the cause then it is included as a nested exception:

com.mongodb.MongoException$Network: can't call something : /127.0.0.1:27017/blah
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:291)
	at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:256)
	at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:289)
	at com.mongodb.DB.command(DB.java:260)
	at com.mongodb.DB.command(DB.java:241)
	at com.mongodb.DB.command(DB.java:282)
	at com.mongodb.DB.command(DB.java:196)
	at com.mongodb.DB.dropDatabase(DB.java:538)
	at com.mongodb.Mongo.dropDatabase(Mongo.java:394)
	at com.mongodb.util.TestCase.cleanup(TestCase.java:144)
	at com.mongodb.util.TestCase.runConsole(TestCase.java:174)
	at com.mongodb.DBCursorTest.main(DBCursorTest.java:514)
Caused by: java.net.SocketTimeoutException: Read timed out
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:129)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
	at org.bson.io.Bits.readFully(Bits.java:46)
	at org.bson.io.Bits.readFully(Bits.java:33)
	at org.bson.io.Bits.readFully(Bits.java:28)
	at com.mongodb.Response.<init>(Response.java:40)
	at com.mongodb.DBPort.go(DBPort.java:124)
	at com.mongodb.DBPort.call(DBPort.java:74)
	at com.mongodb.DBTCPConnector.innerCall(DBTCPConnector.java:282)
	... 11 more

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