Grails Mongo - Tomcat 无法停止创建连接
Grails Mongo - Tomcat fails to stop creating connections
我正在开发 Grails 应用程序,目标是 Grails Mongo 插件。
当我使用 运行-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 线程中获取 Mongo连接,但失败了,但并未关闭该线程。
因此,应用程序每隔约 5 秒打开一个新连接并且 MongoDB 服务器扩展所有可用连接:
> db.serverStatus().connections
{ "current" : 6, "available" : 813, "totalCreated" : NumberLong(800) }
> db.serverStatus().connections
{ "current" : 45, "available" : 774, "totalCreated" : NumberLong(839) }
Mongo 数据库服务器可从该 Tomcat 服务器实例获得,我可以连接到它并检索数据。
还 stacktrace.log 包含下一个错误:
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.access0(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
有人遇到同样的问题吗?
谢谢!
问题是 MongoDB 驱动程序连接设置不正确。
我们的 MongoDB 服务器安装在与 Tomcat 容器相同的实例上。但是我们使用完整的 URL 连接到 MongoDB,例如app.server.com:27017。驱动程序无法建立连接,Tomcat 无法终止连接线程池。
作为这个问题的解决方案,您有 2 种方法:
- 使用本地主机作为连接 URL
- 在 MongoDB 配置文件中设置 bind_ip 参数并在那里提供您的 MongoDB 服务器 IP
我正在开发 Grails 应用程序,目标是 Grails Mongo 插件。 当我使用 运行-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 线程中获取 Mongo连接,但失败了,但并未关闭该线程。
因此,应用程序每隔约 5 秒打开一个新连接并且 MongoDB 服务器扩展所有可用连接:
> db.serverStatus().connections
{ "current" : 6, "available" : 813, "totalCreated" : NumberLong(800) }
> db.serverStatus().connections
{ "current" : 45, "available" : 774, "totalCreated" : NumberLong(839) }
Mongo 数据库服务器可从该 Tomcat 服务器实例获得,我可以连接到它并检索数据。
还 stacktrace.log 包含下一个错误:
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.access0(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
有人遇到同样的问题吗?
谢谢!
问题是 MongoDB 驱动程序连接设置不正确。 我们的 MongoDB 服务器安装在与 Tomcat 容器相同的实例上。但是我们使用完整的 URL 连接到 MongoDB,例如app.server.com:27017。驱动程序无法建立连接,Tomcat 无法终止连接线程池。
作为这个问题的解决方案,您有 2 种方法:
- 使用本地主机作为连接 URL
- 在 MongoDB 配置文件中设置 bind_ip 参数并在那里提供您的 MongoDB 服务器 IP