[JAVA-504] fetchMaxBsonObjectSize incorrectly assumes access to the admin database Created: 11/Jan/12 Updated: 11/Mar/13 Resolved: 11/Mar/13 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Connection Management |
| Affects Version/s: | 2.5.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Peter Robinett | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 1 |
| Labels: | authentication | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Using the library via the Casbah Scala library |
||
| Description |
|
Some Mongo database servers do not give average accounts access to the admin database. This causes problems when attempting to make an authorized connection to a normal database. When attempting to connect to such a machine, I get errors like this: {{Jan 11, 2012 3:56:24 PM com.mongodb.DBTCPConnector fetchMaxBsonObjectSize I can't say what the exact solution is, but it appears that fetchMaxBsonObjectSize() returns a null in this situation, with its unexpected presence (an int is expected) then causing the exception in later commands like DB.authenticate(). |
| Comments |
| Comment by Jeffrey Yemin [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
In order for the connection to work reliably, please ensure that all the IP addresses that DNS returns for the host are accessible from the machine on which you're running the client program. If you were getting a connection exception to 0.0.39.97 reported by the Java driver, it means that at the time you ran the program DNS was reporting that as one of the IP addresses for staff.mongohq.com. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Peter Robinett [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
No, I didn't but since I was able to reproduce the original issue on my local machine once attempting to MongoHQ instead of my local test Mongo instance, I am confident it's the same. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Did you run this test on the same machine that was giving you the connection exception to 0.0.39.97? If so, can you try the test with the Java driver again and see if it's still broken? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Try taking the username/password out of the URI. It is not parsed correctly in 2.5.3. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Peter Robinett [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Stephen's workaround kind of works for me. What doesn't work is the URL parsing:
I can manually connect and authenticate, though:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Peter Robinett [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Jeff, that works fine from my development machine: First
and then
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Please try running this standalone program(replace host and port with whatever you are using for mongo) and paste the output.
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Stephan B [ 06/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Haha, there is a workaround (in Scala): val uri = new MongoURI(System.getenv("MONGOHQ_URL")) val url = uri.getHosts.get(0) log.info("accessing remote MongoDB: {}", uri.getDatabase) log.info("authenticating at remote MongoDB: {}@{}", uri.getUsername, uri.getPassword) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Stephan B [ 05/Mar/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Is this something that will be fixed? I have the exact same problem now when trying to use MongoHQ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Peter Robinett [ 18/Jan/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
To the real address, yes:
To the mysterious 0.0.39.97 address that somehow appears, no:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 18/Jan/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Are you able to telnet to that host and port? You should see something like:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Peter Robinett [ 18/Jan/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
So the null is coming from somewhere else. Hmm... I get a similar but slightly different error if I skip the authentication step. From the Scala REPL:
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Jeffrey Yemin [ 17/Jan/12 ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I don't think this has anything to do with authentication. It's just that DB.authenticate is the first time the driver tries to connect to the server. For example, a simple test program trying to authenticate to a database that is down will generate this stack trace:
For a non-authenticated database, you just get the exception in a later call (like find(...)). Just to be sure, can you confirm that you get the same exception calling find() on a collection in a non-authenticated database? With regard to the actual message in the SocketException, I've never seen that before. I found a couple of threads on it (like http://forums.mysql.com/read.php?39,41308,41308#msg-41308), but I can't vouch for the accuracy. By the way, DBTCPConnector.fetchMaxBsonObjectSize returns 0 if it can't reach the server (since the return value is int, it can't return null). In that case the driver will default to 4MB (com.mongodb.Bytes#MAX_OBJECT_SIZE). |