当前位置: 首页 > 知识库问答 >
问题:

Grails Mongo-Tomcat无法停止创建连接

宋烨烁
2023-03-14

我正在开发Grails应用程序,目标是Grails Mongo插件。当我使用run-app命令在本地运行应用程序时,一切正常,应用程序打开了2个到Mongo实例的连接。

但是当我将应用程序打包到war文件并将其部署到远程Tomcat服务器时,启动应用程序的行为变得非常奇怪。

以下是启动日志:

??? 12, 2015 1:15:59 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/myapp] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
??? 12, 2015 1:15:59 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myapp] appears to have started a thread named [cluster-1-myapp.server:27017] but has failed to stop it. This is very likely to create a memory leak.
??? 12, 2015 1:15:59 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/myapp] appears to have started a thread named [MongoCleaner1332131781] but has failed to stop it. This is very likely to create a memory leak.
??? 12, 2015 1:15:59 PM org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /data/tomcat3/webapps/myapp.war has finished in 40,759 ms
??? 12, 2015 1:16:04 PM org.apache.catalina.loader.WebappClassLoader loadClass
INFO: Illegal access: this web application instance has been stopped already.  Could not load org.bson.io.PoolOutputBuffer.  The eventual following stack trace is caused by an error thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access, and has no functional impact.
java.lang.IllegalStateException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1612)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
    at org.bson.BasicBSONDecoder.<init>(BasicBSONDecoder.java:599)
    at com.mongodb.DefaultDBDecoder.<init>(DefaultDBDecoder.java:44)
    at com.mongodb.DefaultDBDecoder$DefaultFactory.create(DefaultDBDecoder.java:33)
    at com.mongodb.DBPort.<init>(DBPort.java:90)
    at com.mongodb.ServerMonitor$ServerMonitorRunnable.run(ServerMonitor.java:87)
    at java.lang.Thread.run(Thread.java:745)

??? 12, 2015 1:16:29 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
??? 12, 2015 1:16:29 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/app] startup failed due to previous errors

所以,在启动过程中,应用程序尝试在单独的Java线程中获取MongoConnection,但失败了,但没有关闭该线程。

因此,每5秒钟应用程序就会打开一个新的连接,MongoDB服务器就会消耗所有可用的连接:

> db.serverStatus().connections
{ "current" : 6, "available" : 813, "totalCreated" : NumberLong(800) }
> db.serverStatus().connections
{ "current" : 45, "available" : 774, "totalCreated" : NumberLong(839) }

Mongo DB Server可从该Tomcat服务器实例获得,我可以连接到它并检索数据。

还有stacktrace。日志包含下一个错误:

Caused by: com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=mongodb.host:27017, type=Unknown, state=Connecting}]
    at com.mongodb.BaseCluster.getServer(BaseCluster.java:82)
    at com.mongodb.DBTCPConnector.getServer(DBTCPConnector.java:650)
    at com.mongodb.DBTCPConnector.access$300(DBTCPConnector.java:39)
    at com.mongodb.DBTCPConnector$MyPort.getConnection(DBTCPConnector.java:499)
    at com.mongodb.DBTCPConnector$MyPort.get(DBTCPConnector.java:447)
    at com.mongodb.DBTCPConnector.authenticate(DBTCPConnector.java:620)
    at com.mongodb.DBApiLayer.doAuthenticate(DBApiLayer.java:195)
    at com.mongodb.DB.authenticateCommandHelper(DB.java:765)
    at com.mongodb.DB.authenticate(DB.java:721)
    at org.grails.datastore.gorm.mongo.bean.factory.GMongoFactoryBean.afterPropertiesSet(GMongoFactoryBean.java:149)
    ... 5 more

有人面临同样的问题吗?

谢谢你!

共有1个答案

壤驷鸿
2023-03-14

问题是MongoDB驱动程序连接的设置不正确。我们的MongoDB服务器与Tomcat容器安装在同一个实例上。但我们使用完整的URL连接到MongoDB,例如应用程序。服务器通讯:27017。驱动程序无法建立连接,Tomcat无法终止连接线程池。

为了解决这个问题,您可以通过两种方式:

  1. 使用localhost作为连接URL
  2. 在MongoDB配置文件中设置bind_ip参数,并在那里提供MongoDB服务器ip
 类似资料:
  • 我试图在独立模式下部署Hbase以下这篇文章:http://hbase.apache.org/book.html#quickstart.版本是0.92.1-cdh4.1.2 但我得到这些错误时,试图创建一个表: 错误消息: 输出日志: 我的配置: > 在hbase env中添加了JAVA_HOME。上海 hbase_网站。xml 我试图修改/etc/hosts,它看起来像这样(oracle是主机名

  • 我正在尝试解决一个关于将Apache和Tomcat与mod\u proxy\u ajp连接的问题。在我的例子中,Tomcat停止响应Apache,Apache日志打印错误消息,如下所示: 我不知道。有人能帮我吗?

  • 我正在尝试使用快速连接将JProfiler(10.0.1)连接到JMX端口- “另一个应用程序正在端口19002上运行。请检查您的端口配置”。 我使用的是oracle JDK jdk1.8.0_181。下面是我用于服务器启动的JXM选项。

  • 在试图通过浏览器访问我的应用程序时,我遇到了不少错误。错误包括: 无法自动连线方法:public void com。ProjectOne。Util。自定义HibernatedAOSupport。anyMethodName(org.hibernate.SessionFactory);嵌套的异常是org。springframework。豆。工厂NoSuchBeanDefinitionException

  • 问题内容: 我可以使用成功启动,文档中提到可以正常退出应用程序hit ctrl-c。 Maven进程确实终止了,但是Tomcat仍在运行,我仍然可以访问该网页。当我再次尝试启动spring-boot时,由于端口正在使用中,因此无法启动Tomcat。 要继续,我必须手动终止正在运行的进程。这是一个错误还是我错过了什么? 问题答案: 我仍然在Windows 7上运行的1.1.9版本上碰巧。 因此,在按

  • 要继续,我必须手动终止正在运行的进程。这是一个窃听器还是我遗漏了什么?