Endless MongoDB ReplicaSetStatus updater exceptions using the Java driver in Spring
I just deployed a Spring web application onto Glassfish. This app contains an injected Spring bean for the Mongo object, which is pretty basic, it just looks like this:
<bean id="mongo" class="com.mongodb.Mongo">
<constructor-arg value="127.0.0.1" />
<constructor-arg value="27017" />
</bean>
I fire up my web app, then use this Mongo object to query the db and insert records and whatnot.. and everything works fine.
But in my server.log file I get and endless stream of SE开发者_如何学GoVERE
error messages. They are NullPointerException
s and IOException
s. They appear to have something to do with ReplicaSetStatus, but I don't know why it keeps trying to connect, is it turn on be default?
Does anyone know what causes these? How can I fix the problem, or stop whatever is causing them?
// EDIT: The exceptions start immediately after I deploy my application. But they do not stop when I disable my application, or even undeploy it.
These messages just get written constantly, but from what I can see theres only 4 types of errors:
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: 27017:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb..updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:263)
|#]
[#|2011-04-22T17:49:40.818+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=37;_ThreadName=Thread-1;|can't update node: localhost:27017
java.lang.NullPointerException
at com.mongodb.OutMessage.reset(OutMessage.java:73)
at com.mongodb.OutMessage.<init>(OutMessage.java:51)
at com.mongodb.OutMessage.query(OutMessage.java:38)
at com.mongodb.DBPort.findOne(DBPort.java:127)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 127.0.0.1:27017
java.io.IOException: couldn't connect to [/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
[#|2011-04-22T17:49:41.676+0900|SEVERE|glassfish3.1|com.mongodb.ReplicaSetStatus|_ThreadID=48;_ThreadName=Thread-1;|can't update node: 27017:27017
java.io.IOException: couldn't connect to [/0.0.105.137:27017] bc:java.net.SocketException: Network is unreachable: connect
at com.mongodb.DBPort._open(DBPort.java:206)
at com.mongodb.DBPort.go(DBPort.java:94)
at com.mongodb.DBPort.go(DBPort.java:75)
at com.mongodb.DBPort.findOne(DBPort.java:129)
at com.mongodb.DBPort.runCommand(DBPort.java:138)
at com.mongodb.ReplicaSetStatus$Node.update(ReplicaSetStatus.java:149)
at com.mongodb.ReplicaSetStatus.updateAll(ReplicaSetStatus.java:314)
at com.mongodb.ReplicaSetStatus.ensureMaster(ReplicaSetStatus.java:306)
at com.mongodb.DBTCPConnector.checkMaster(DBTCPConnector.java:383)
at com.mongodb.ReplicaSetStatus$Updater.run(ReplicaSetStatus.java:275)
|#]
Change your Mongo bean definition in Spring context file as here:
<constructor-arg value="${db.host}" type="java.lang.String" />
<constructor-arg value="${db.port}" type="int" />
If you omit type attributes, another Mongo class constructor is invoked, where arguments are instances of com.mongodb.ServerAddress type, and 27017 is treated as a hostname and InetAddress.getAllByName( host ) resolves to this IP 0.0.105.137.
精彩评论