Play 应用因反应性 mongo 更新操作而终止
The play app terminates for reactive mongo update operation
package models
import play.api.libs.json.{Json, OFormat}
import reactivemongo.bson.{BSONLong, BSONObjectID}
case class SavedPostOrBlog(
_id:Option[BSONObjectID],
postOrBlogId:BSONObjectID,
discussGroupId:Option[BSONObjectID],
saverId:BSONObjectID,
isQPost:Option[Boolean]=None,
isArticle:Option[Boolean]=None,
test : BSONLong = BSONLong.apply(12334)
)
object SavedPostOrBlogJsonFormat{
import reactivemongo.play.json._
implicit val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]
}
[error] a.a.ActorSystemImpl - Uncaught error from thread [application-dbContext-
dispatcher-37]: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoSuchMethodError: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V
at controllers.postActions.SavePostController.$anonfun$savePost(SavePostController.scala:96)
at controllers.postActions.SavePostController.checkDGroupMemberShip(SavePostController.scala:157)
at controllers.postActions.SavePostController.$anonfun$savePost(SavePostController.scala:93)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:433)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run(BatchingExecutor.scala:92)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:92)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
[info] p.c.s.AkkaHttpServer - Stopping server...
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi stopping...
[INFO] [04/02/2020 12:49:00.178] [reactivemongo-akka.actor.default-dispatcher-12] [akka://reactivemongo/user/Connection-1] Message [reactivemongo.core.actors.ChannelDisconnected] without sender to Actor[akka://reactivemongo/user/Connection-1#1685282110] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://reactivemongo/user/Connection-1#1685282110]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[info] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Stopping the MongoDBSystem
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi connections are stopped
[info] r.api.Driver - [Supervisor-2] Closing instance of ReactiveMongo driver
[info] r.api.Driver - [Supervisor-2] Stopping the monitor...
[DEBUG] [04/02/2020 12:49:00.182] [reactivemongo-akka.actor.default-dispatcher-2] [EventStream] shutting down: StandardOutLogger
[info] r.c.n.ChannelFactory - [Supervisor-2/Connection-1] Cannot create channel to '127.0.0.1:27017' from inactive factory
[warn] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Cannot create connection for Node(127.0.0.1:27017,Primary,Vector(Connection([id: 0x03a83e6d, L:0.0.0.0/0.0.0.0:58166 ! R:/127.0.0.1:27017],Connecting,Set(Authenticated(admin,dbReadWrite)),None)),Set(Authenticated(admin,dbReadWrite)),None,ProtocolMetadata(2.6, 3.6),PingInfo(6760584, 0, -1, None),false)
reactivemongo.core.errors.GenericDriverException: MongoError['Cannot create channel to '127.0.0.1:27017' from inactive factory (Supervisor-2/Connection-1)']
没有 test
属性 in SavedPostOrBlog
模型查询运行正常,但是当我添加 BSONLong
的测试 属性 时,jvm 崩溃。
这里是查询:
def createDocument(postOrBlogId: BSONObjectID,
saverId: BSONObjectID, savedPostOrBlog: SavedPostOrBlog): Future[UpdateWriteResult] =
collection.map(_.update(true).one(Json.obj("postOrBlogId" -> postOrBlogId, "saverId" -> saverId), savedPostOrBlog, upsert = true)).flatten
reactiveMongo 依赖项:"org.reactivemongo" %% "play2-reactivemongo" % "0.18.4-play27"
我有一个类似的问题,如果我在查询字段中输入某个值,查询就会崩溃,如果我没有输入这个特定值,查询就会崩溃。
事实证明,我创建的序列化程序缺少此字段到 JSON(或文档)
的序列化
而且我没有收到相应的错误,但不得不进行调试才能弄清楚...
我认为:
隐式 val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]
还不够,尝试为 BSONLong 提供 OFormat 作为隐式 val
问题是在开发阶段我们尝试通过编译命令或热重载在sbt中编译时,有时会发生
- 编译器遗漏了一些缺少方法的错误,并显示编译成功,但事实并非如此。
- 有时编译器无法创建编译时 reactive-mongo 的某些宏活动,因此在运行时找不到某些方法。
这两个我找到了应用程序崩溃的原因。
如果我再次清理并编译项目——要么能够捕捉到第一次未发现的错误,要么在出现第二个问题的情况下与模型相关的宏活动将正确完成。因此运行时错误将被删除。
package models
import play.api.libs.json.{Json, OFormat}
import reactivemongo.bson.{BSONLong, BSONObjectID}
case class SavedPostOrBlog(
_id:Option[BSONObjectID],
postOrBlogId:BSONObjectID,
discussGroupId:Option[BSONObjectID],
saverId:BSONObjectID,
isQPost:Option[Boolean]=None,
isArticle:Option[Boolean]=None,
test : BSONLong = BSONLong.apply(12334)
)
object SavedPostOrBlogJsonFormat{
import reactivemongo.play.json._
implicit val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]
}
[error] a.a.ActorSystemImpl - Uncaught error from thread [application-dbContext-
dispatcher-37]: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V, shutting down JVM since 'akka.jvm-exit-on-fatal-error' is enabled for ActorSystem[application]
java.lang.NoSuchMethodError: models.SavedPostOrBlog.<init>(Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lreactivemongo/bson/BSONObjectID;Lscala/Option;Lscala/Option;)V
at controllers.postActions.SavePostController.$anonfun$savePost(SavePostController.scala:96)
at controllers.postActions.SavePostController.checkDGroupMemberShip(SavePostController.scala:157)
at controllers.postActions.SavePostController.$anonfun$savePost(SavePostController.scala:93)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:433)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run(BatchingExecutor.scala:92)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:94)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:92)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:41)
[info] p.c.s.AkkaHttpServer - Stopping server...
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi stopping...
[INFO] [04/02/2020 12:49:00.178] [reactivemongo-akka.actor.default-dispatcher-12] [akka://reactivemongo/user/Connection-1] Message [reactivemongo.core.actors.ChannelDisconnected] without sender to Actor[akka://reactivemongo/user/Connection-1#1685282110] was not delivered. [1] dead letters encountered. If this is not an expected behavior, then [Actor[akka://reactivemongo/user/Connection-1#1685282110]] may have terminated unexpectedly, This logging can be turned off or adjusted with configuration settings 'akka.log-dead-letters' and 'akka.log-dead-letters-during-shutdown'.
[info] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Stopping the MongoDBSystem
[info] p.m.r.DefaultReactiveMongoApi - ReactiveMongoApi connections are stopped
[info] r.api.Driver - [Supervisor-2] Closing instance of ReactiveMongo driver
[info] r.api.Driver - [Supervisor-2] Stopping the monitor...
[DEBUG] [04/02/2020 12:49:00.182] [reactivemongo-akka.actor.default-dispatcher-2] [EventStream] shutting down: StandardOutLogger
[info] r.c.n.ChannelFactory - [Supervisor-2/Connection-1] Cannot create channel to '127.0.0.1:27017' from inactive factory
[warn] r.c.a.MongoDBSystem - [Supervisor-2/Connection-1] Cannot create connection for Node(127.0.0.1:27017,Primary,Vector(Connection([id: 0x03a83e6d, L:0.0.0.0/0.0.0.0:58166 ! R:/127.0.0.1:27017],Connecting,Set(Authenticated(admin,dbReadWrite)),None)),Set(Authenticated(admin,dbReadWrite)),None,ProtocolMetadata(2.6, 3.6),PingInfo(6760584, 0, -1, None),false)
reactivemongo.core.errors.GenericDriverException: MongoError['Cannot create channel to '127.0.0.1:27017' from inactive factory (Supervisor-2/Connection-1)']
没有 test
属性 in SavedPostOrBlog
模型查询运行正常,但是当我添加 BSONLong
的测试 属性 时,jvm 崩溃。
这里是查询:
def createDocument(postOrBlogId: BSONObjectID,
saverId: BSONObjectID, savedPostOrBlog: SavedPostOrBlog): Future[UpdateWriteResult] =
collection.map(_.update(true).one(Json.obj("postOrBlogId" -> postOrBlogId, "saverId" -> saverId), savedPostOrBlog, upsert = true)).flatten
reactiveMongo 依赖项:"org.reactivemongo" %% "play2-reactivemongo" % "0.18.4-play27"
我有一个类似的问题,如果我在查询字段中输入某个值,查询就会崩溃,如果我没有输入这个特定值,查询就会崩溃。
事实证明,我创建的序列化程序缺少此字段到 JSON(或文档)
的序列化而且我没有收到相应的错误,但不得不进行调试才能弄清楚...
我认为:
隐式 val spb: OFormat[SavedPostOrBlog] = Json.format[SavedPostOrBlog]
还不够,尝试为 BSONLong 提供 OFormat 作为隐式 val
问题是在开发阶段我们尝试通过编译命令或热重载在sbt中编译时,有时会发生
- 编译器遗漏了一些缺少方法的错误,并显示编译成功,但事实并非如此。
- 有时编译器无法创建编译时 reactive-mongo 的某些宏活动,因此在运行时找不到某些方法。
这两个我找到了应用程序崩溃的原因。 如果我再次清理并编译项目——要么能够捕捉到第一次未发现的错误,要么在出现第二个问题的情况下与模型相关的宏活动将正确完成。因此运行时错误将被删除。