我在 prod 环境中遇到严重的 IllegalStateException 错误(底部的堆栈跟踪)。在本地,在 dev 上一切正常,我在本地从未遇到过这段代码的任何问题。
Prod 和 Dev 配置具有相同的 Tomcat 5。在 dev 上我有 PostgreSQL 9.2 和 prod 8.4。Pod 环境是某些主机上的 VPS。
导致它的代码是一个简单的类实例创建者(GameStateTransition 类)——它负责初始化和保存超过 370 000 个实例。导致错误的行是 save(flush:true) 或 hibernateSesion.flush() - 我尝试了这两个选项。
错误发生的不确定性 - 有时在创建 160 000 个实例之后,有时在 220 000 之后,有时在 300 000 之后......
我认为这可能是内存问题,VPS 服务器杀死了最消耗内存的进程,但是将 JAVA_OPTS Xmx 更改为 256m,远低于服务器的 500m 限制,但没有帮助。在本地运行应用程序并将开发数据库更改为生产 Postgres 8.4 工作正常(该过程完成且没有错误)所以它一定是产品服务器上的应用程序有问题。
任何人都有任何线索,它可能是关于什么的?
stacktrace 说的是关于 mongoDB、测试和模拟注释的内容,但我没有使用其中的任何一个。这是一个创建实例并将其保存到数据库的简单代码。
2013-02-08 00:07:50 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-12200"]
2013-02-08 00:07:50 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
2013-02-08 00:07:50 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
2013-02-08 00:07:50 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:51 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52,979 [http-bio-12200-exec-6] ERROR errors.GrailsExceptionResolver - IllegalStateException occurred when processing request: [GET] /gameState/initializeTransitionMatrix
Method on class [pl.edu.caspar.analyzer.GameStateTransition] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.. Stacktrace follows:
java.lang.IllegalStateException: Method on class [pl.edu.caspar.analyzer.GameStateTransition] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
at org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener.onApplicationEvent(AbstractPersistenceEventListener.java:46)
at pl.edu.caspar.analyzer.GameStateController$_initializeTransitionMatrix_closure3_closure8.doCall(GameStateController.groovy:59)
at pl.edu.caspar.analyzer.GameStateController$_initializeTransitionMatrix_closure3.doCall(GameStateController.groovy:53)
at pl.edu.caspar.analyzer.GameStateController.initializeTransitionMatrix(GameStateController.groovy:52)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)