带有 Elastic Beanstalk 和 Tomcat 的 AWS RDS -“从服务器成功接收的最后一个数据包是 ___ 秒前”
Posted
技术标签:
【中文标题】带有 Elastic Beanstalk 和 Tomcat 的 AWS RDS -“从服务器成功接收的最后一个数据包是 ___ 秒前”【英文标题】:AWS RDS with Elastic Beanstalk and Tomcat - "The last packet successfully received from the server was ___ seconds ago" 【发布时间】:2018-01-05 20:19:29 【问题描述】:感谢您提供的任何见解。我是系统管理的新手,陷入了困境。
我有一个使用 Amazon Web Services 的 RDS 实例。它托管一个 mysql 5.6 数据库。我的 Elastic Beanstalk 应用程序正在运行带有 Tomcat 8/Java 8 的 Linux 服务器。我的 Web 应用程序使用 Hibernate 与数据库通信。在我的 Hibernate.cfg.xml 文件中,我已将“autoReconnect=true”添加到我的数据库链接中,但这并没有帮助。
有谁知道这个错误,可以告诉我可能是什么原因造成的吗?
type Exception report
message Request processing failed; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
description The server encountered an internal error that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
org.hibernate.exception.JDBCConnectionException: could not execute query
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
org.hibernate.loader.Loader.doList(Loader.java:2536)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
org.hibernate.loader.Loader.list(Loader.java:2271)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
com.grandcircus.spring.util.dao.ChaplainDAO.getByEmail(ChaplainDAO.java:32)
com.grandcircus.spring.util.dao.DAO.getUserType(DAO.java:68)
com.grandcircus.spring.controller.HomeController.loginFormSubmit(HomeController.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was273873 seconds ago.The last packet sent successfully to the server was 273873 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)
com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
org.hibernate.loader.Loader.doQuery(Loader.java:802)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
org.hibernate.loader.Loader.doList(Loader.java:2533)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
org.hibernate.loader.Loader.list(Loader.java:2271)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
com.grandcircus.spring.util.dao.ChaplainDAO.getByEmail(ChaplainDAO.java:32)
com.grandcircus.spring.util.dao.DAO.getUserType(DAO.java:68)
com.grandcircus.spring.controller.HomeController.loginFormSubmit(HomeController.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
root cause
java.net.SocketException: Broken pipe (Write failed)
java.net.SocketOutputStream.socketWrite0(Native Method)
java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111)
java.net.SocketOutputStream.write(SocketOutputStream.java:155)
java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
org.hibernate.loader.Loader.doQuery(Loader.java:802)
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
org.hibernate.loader.Loader.doList(Loader.java:2533)
org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
org.hibernate.loader.Loader.list(Loader.java:2271)
org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:119)
org.hibernate.impl.SessionImpl.list(SessionImpl.java:1716)
org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:347)
org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:369)
com.grandcircus.spring.util.dao.ChaplainDAO.getByEmail(ChaplainDAO.java:32)
com.grandcircus.spring.util.dao.DAO.getUserType(DAO.java:68)
com.grandcircus.spring.controller.HomeController.loginFormSubmit(HomeController.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:222)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:814)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:737)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:969)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
正如 Deepak 所建议的,这是一个连接池问题。我按照我的 MKYong 提供的有关该主题的步骤进行操作,这纠正了问题。在这里阅读更多:
https://www.mkyong.com/hibernate/how-to-configure-the-c3p0-connection-pool-in-hibernate/
【问题讨论】:
根据错误,您正在尝试使用在某一时刻与数据库建立的连接,但已完全未使用且空闲超过 3 天。 (!?)那么...在此消息出现之前的 3 天后,您添加了&autoReconnect=true
?还是有可能在进行更改时您的服务没有重新启动?
目前,当我重新启动弹性 beantalk 服务器时,计时器开始计时,而不是在我访问弹性 beantalk 应用程序的网站时重新连接。所以,我在三天前重新启动了我的服务器,它从那里超时了。我从一开始就在我的项目中设置了 autoReconnect=true。
这是有道理的。我认为下面的答案已经正确评估了这不是 AWS、RDS 或 EB 所特有的问题,但是您的连接池没有正确维护其池连接,并且给您带来了一个没有帮助的错误。可能有用:dev.mysql.com/doc/connector-j/5.1/en/…
看准了!我要检查一下,然后等待看看错误是否再次出现。我会在大约 6 个多小时后回来查看。
见28800 seconds。随意发布您的发现作为答案(假设它有效),因为您是真正的工作人员,在这里。
【参考方案1】:
此问题与 AWS 或 RDS 或 beanstalk 无关。这是一个典型的连接池问题。
确定这是否是池问题;尝试重新启动您的tomcat ..这个问题应该会消失。如果是,请尝试谷歌搜索该问题;你会发现很多帮助,比如How to configure c3p0 in hibernate to auto-refresh stale DB connections
【讨论】:
谢谢迪帕克!我要试一试,看看这是否是解决方案。由于该消息需要一些时间才能重新出现,因此我将定期检查该站点,并在几个小时后返回此处投票+如果解决了该问题。再次感谢您! 这解决了这个问题。重新启动服务器后,我坐在 7 个半小时后,该站点仍在运行。谢谢迪帕克!以上是关于带有 Elastic Beanstalk 和 Tomcat 的 AWS RDS -“从服务器成功接收的最后一个数据包是 ___ 秒前”的主要内容,如果未能解决你的问题,请参考以下文章
带有 docker 应用程序的 AWS Elastic Beanstalk 返回 502
带有 Elastic Beanstalk CLI 的 WordPress
带有 docker 的 AWS Elastic Beanstalk 版本不正确
如何使用 AWS Elastic Beanstalk 在 URL 中运行带有参数的 PHP 脚本?