我正在使用 mongohq 作为 Heroku 插件,最近在本地主机上运行我的应用程序时遇到了一些问题。只要我的应用程序尝试访问数据库,我就会不断收到以下堆栈跟踪。
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[Network: can't call something : staff.mongohq.com/50.17.135.240:10050/app4620908]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:82) [play_2.9.1.jar:2.0]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:63) [play_2.9.1.jar:2.0]
at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor.jar:2.0]
at play.core.ActionInvoker.apply(Invoker.scala:61) [play_2.9.1.jar:2.0]
at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor.jar:2.0]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor.jar:2.0]
Caused by: com.mongodb.MongoException$Network: can't call something : staff.mongohq.com/50.17.135.240:10050/app4620908
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:227) ~[mongo-java-driver-2.7.3.jar:na]
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305) ~[mongo-java-driver-2.7.3.jar:na]
at com.mongodb.DB.command(DB.java:160) ~[mongo-java-driver-2.7.3.jar:na]
at com.mongodb.DB.command(DB.java:183) ~[mongo-java-driver-2.7.3.jar:na]
at com.mongodb.DBCollection.getCount(DBCollection.java:864) ~[mongo-java-driver-2.7.3.jar:na]
at com.mongodb.DBCollection.getCount(DBCollection.java:835) ~[mongo-java-driver-2.7.3.jar:na]
Caused by: java.net.SocketException: Operation timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.6.0_31]
at java.net.SocketInputStream.read(SocketInputStream.java:129) ~[na:1.6.0_31]
at java.io.BufferedInputStream.fill(BufferedInputStream.java:218) ~[na:1.6.0_31]
at java.io.BufferedInputStream.read1(BufferedInputStream.java:258) ~[na:1.6.0_31]
at java.io.BufferedInputStream.read(BufferedInputStream.java:317) ~[na:1.6.0_31]
at org.bson.io.Bits.readFully(Bits.java:35) ~[mongo-java-driver-2.7.3.jar:na]
我直接使用 Mongo 驱动程序,并确保只创建一个单例 Mongo 实例,并且我已经验证它正在创建。据我所知,它仅在我请求数据时发生
在对用户进行身份验证时,它发生在以下两行中的第二行:
DBCollection users = DBManager.getDB("mojulo").getCollection("users"); /*Get the Mongo singleton then get the "users" collection */
DBObject user = users.findOne(new BasicDBObject("username", username)); /*find the user with the specified username */
When trying to register a user, it occurs after I attempt the insert, and the insert is not successful. on the second of these two lines:
WriteResult result = users.insert(new_user); /* attempt to insert a new user */
if(result.getLastError().ok()){ /* make sure it worked, error occurs on this line */
...
我在这里相当一无所知,我觉得可能存在线程问题?因为它随机工作一次,但随后停止工作。任何人都可以对此有所了解,将不胜感激
编辑:
希望我能更明确地说明我在这里遇到的问题,但它们非常零星。它似乎有 10% 的时间可以工作,然后停止工作。