简体   繁体   English

Tomcat + Hibernate + JNDI + Azure DB - 通过对等方重置连接:套接字写入错误

[英]Tomcat + Hibernate + JNDI + Azure DB - Connection reset by peer: socket write error

here an error which drives me crazy, which seems to have tons of related entries but non solution worked so far. 这里出现了一个让我疯狂的错误,这似乎有很多相关的条目,但到目前为止还没有解决方案。 Maybe there is something special about my configuration I haven't found so far... 也许我的配置有一些特别之处我到目前为止还没找到...

Im running a Java application, using Hibernation (5.0.3.Final) connected an Azure SQL DB (v12) via JNDI ressources (tomcat 8.0.28). 我运行Java应用程序,使用Hibernation(5.0.3.Final)通过JNDI ressources(tomcat 8.0.28)连接Azure SQL DB(v12)。 I am receiving, as it looks randomly, Connection reset by peer: socket write error 's followed by The connection is closed errors. 我收到的,因为它看起来是随机的, Connection reset by peer: socket write error后跟The connection is closed错误。 The app does not recover until restart... 应用程序直到重新启动才恢复...

This happens despite the fact that i have configured a validationQuery and also set testOnCreate , testOnBorrow and testWhileIdle to true. 尽管我已配置了validationQuery并将testOnCreatetestOnBorrowtestWhileIdle为true,但testOnBorrow发生这种情况。

I'll give you the whole configuration below. 我将在下面给你完整的配置。 This really drives me crazy as this seems to be a bug which is well known but not solved since years?! 这真的让我发疯,因为这似乎是一个众所周知但多年未解决的错误?!

Here's the configuration: 这是配置:

server.xml : server.xml

 <Resource name="jdbc/booking"
     global="jdbc/booking"
     auth="Container"
     username="XXX"
     password="YYY"
     type="javax.sql.XADataSource"
     driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
     url="jdbc:sqlserver://mydatabase.database.windows.net:1433;database=booking;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"
     factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
     maxWait="10000"
     validationQuery="SELECT 1"
     testOnCreate="true"
     testOnBorrow="true"
     testWhileIdle="true"
     timeBetweenEvictionRunsMillis="30000"
     minEvictableIdleTimeMillis="60000"
     validationInterval="1000"
     removeAbandonedOnMaintenance="true"
     fastFailValidation="true"/>

context.xml (in web/META-INF/ of the war) context.xml (在web / META-INF /战争中)

<ResourceLink name="jdbc/booking" global="jdbc/booking"/> 

hibernate.cfg

<property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
<property name="connection.datasource">java:comp/env/jdbc/booking</property>

I'm setting up the Hibernate session factory like this: 我正在设置这样的Hibernate会话工厂:

private void setUp() {
    final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure( AzureDB.configFile ).build();
    try {
        this.sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
    } catch ( final Exception e ) {
        System.err.println( e.getMessage() );
        StandardServiceRegistryBuilder.destroy( registry );
        System.exit( 666 );
    }
}

and use it via injection in my services like this: 并在我的服务中通过注入使用它,如下所示:

@Inject private AzureDB           bookingDB;

...

this.bookingDB.getCurrentSession().beginTransaction();
final Hotel hotel = this.bookingDB.getCurrentSession().get( Hotel.class, hotelId );

One request will finish successfully, the next will run into the Connection rest by peer error. 一个请求将成功完成,下一个请求将进入Connection rest by peer错误。 A full stracktrace will look like this: 完整的stracktrace将如下所示:

16-Nov-2015 09:26:59.028 WARN [http-apr-8080-exec-13] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions SQL Error: 0, SQLState: 08S01
16-Nov-2015 09:26:59.028 ERROR [http-apr-8080-exec-13] org.hibernate.engine.jdbc.spi.SqlExceptionHelper.logExceptions Connection reset by peer: socket write error
16-Nov-2015 09:26:59.044 INFO [http-apr-8080-exec-13] org.hibernate.event.internal.DefaultLoadEventListener.onLoad HHH000327: Error performing load command : org.hibernate.exception.JDBCConnectionException: could not extract ResultSet
16-Nov-2015 09:26:59.060 SEVERE [http-apr-8080-exec-13] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [com.nekst.service.nekstAPI] in context with path [] threw exception [org.hibernate.exception.JDBCConnectionException: could not extract ResultSet] with root cause
 com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset by peer: socket write error
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1748)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1732)
    at com.microsoft.sqlserver.jdbc.TDSChannel.write(IOBuffer.java:1842)
    at com.microsoft.sqlserver.jdbc.TDSWriter.flush(IOBuffer.java:4161)
    at com.microsoft.sqlserver.jdbc.TDSWriter.writePacket(IOBuffer.java:4062)
    at com.microsoft.sqlserver.jdbc.TDSWriter.endMessage(IOBuffer.java:3107)
    at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:6700)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:424)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:372)
    at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:6276)
    at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1793)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:184)
    at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:159)
    at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.executeQuery(SQLServerPreparedStatement.java:284)
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.getResultSet(AbstractLoadPlanBasedLoader.java:433)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeQueryStatement(AbstractLoadPlanBasedLoader.java:185)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:120)
    at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:85)
    at org.hibernate.loader.entity.plan.AbstractLoadPlanBasedEntityLoader.load(AbstractLoadPlanBasedEntityLoader.java:167)
    at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3954)
    at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:488)
    at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:453)
    at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:196)
    at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:258)
    at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:134)
    at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1071)
    at org.hibernate.internal.SessionImpl.access$2600(SessionImpl.java:164)
    at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2638)
    at org.hibernate.internal.SessionImpl.get(SessionImpl.java:955)
    at sun.reflect.GeneratedMethodAccessor160.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
    at com.sun.proxy.$Proxy138.get(Unknown Source)
    at com.nekst.service.rest.Kauai.getLocation(Kauai.java:227)
    at com.nekst.service.rest.Kauai.getRecommendation(Kauai.java:65)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:144)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:161)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:160)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:99)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:389)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:347)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:326)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:471)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:425)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:383)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:336)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:223)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:217)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
    at com.googlecode.psiprobe.Tomcat80AgentValve.invoke(Tomcat80AgentValve.java:45)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2503)
    at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2492)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)

followed by com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed. 然后是com.microsoft.sqlserver.jdbc.SQLServerException: The connection is closed. on any succeeding request. 在任何后续请求。

There can be weeks of undisturbed service and then (like currently) I see this errors continuously... Has anybody experience in this concrete setting or any other remarks to my situation? 可能会有数周的不受干扰的服务,然后(就像目前一样)我不断看到这个错误......有没有人在这个具体设置或任何其他评论中遇到过我的情况? Help is appreciated a lot... 非常感谢帮助......

UPDATE: I also tried adding custom registry entries as suggested here: https://msdn.microsoft.com/en-us/library/hh290696(v=SQL.110).aspx , no luck, I can see the keepalives in wireshark, but still getting those errors 更新:我也尝试添加自定义注册表项,如下所示: https//msdn.microsoft.com/en-us/library/hh290696(v = SQL.110).aspx,没有运气,我可以在wireshark中看到keepalives ,但仍然得到这些错误

Per my experience, the issue was generally caused by using the unsuitable configuration for the JDBC connection pool in JNDI. 根据我的经验,问题通常是由于在JNDI中使用JDBC连接池的不合适配置引起的。

There is a offical doc for the Azure SQL Database resource limits https://azure.microsoft.com/en-us/documentation/articles/sql-database-resource-limits/ . Azure SQL数据库资源限制有一个官方文档https://azure.microsoft.com/en-us/documentation/articles/sql-database-resource-limits/

I checked your JNDI configuration. 我检查了你的JNDI配置。 So I suggest you can refer to your Azure service tier's limits and the Tomcat doc for JDBC data source settings in JNDI https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JDBC_Data_Sources to set the configuration properties initialSize , maxActive , minIdle and maxIdle to suitable values like maxIdle=100 . 所以我建议你可以参考你的Azure服务层的限制和JNDI中的JDBC数据源设置的Tomcat doc https://tomcat.apache.org/tomcat-7.0-doc/jndi-resources-howto.html#JDBC_Data_Sources来设置配置属性initialSizemaxActiveminIdlemaxIdle为合适的值,如maxIdle=100

Update: 更新: 在此输入图像描述

The initialSize & minIdle default value is 0. The minIdle property control the pool connection minimal count when the pool release the connection with low concurrent access. initialSizeminIdle默认值为0.当池释放具有低并发访问权限的连接时, minIdle属性控制池连接最小计数。 If the pool connection released till 0, the new access will cause the issue connection reset . 如果池连接释放到0,则新访问将导致问题connection reset

Updated at 2015.11.19: 更新于2015.11.19:

There is an excerpt explained the issue Connection reset by peer . 有一段摘录解释了Connection reset by peer的问题。

[10054] Connection reset by peer [10054]由对等方重置连接

Connection reset by peer is a tough one because it can be caused by so many things. 由同行重置连接是一个艰难的,因为它可能是由很多东西引起的。 In all cases, the server determines that the socket is no longer good and closes it from its side. 在所有情况下,服务器都确定套接字不再好,并从侧面关闭它。

Write Error 写错误

Scenario: Mary was trying to talk to Joe but didn't think she was getting through, so she hung rather than lose his messages (data). 场景:玛丽试图和乔交谈,但她认为她没有通过,所以她挂了而不是丢失他的消息(数据)。 A write error occurs when a server cannot successfully write to a user's client. 当服务器无法成功写入用户的客户端时,会发生写入错误。 When the server receives information, it usually responds with information of its own. 当服务器接收信息时,它通常会响应自己的信息。 When the server receives an error when writing to a client, it then disconnects the user, resulting in a write error quit message similar to the read error format. 当服务器在写入客户端时收到错误时,它会断开用户连接,从而导致写入错误退出消息,类似于读取错误格式。

Try to set the Idle timeout value to some large value. 尝试将空闲超时值设置为某个较大的值。 Do you observe any pattern as to when this issue occurs? 您是否观察到此问题发生时的任何模式? Is there a idle state after which you see this problem? 是否存在空闲状态,之后您会看到此问题? Check - http://www.coderanch.com/t/633566/JDBC/databases/microsoft-sqlserver-jdbc-SQLServerException-Connection 检查 - http://www.coderanch.com/t/633566/JDBC/databases/microsoft-sqlserver-jdbc-SQLServerException-Connection

This also explains the same behavior due to timeout - DBCP returns closed connections 这也解释了由于超时导致的相同行为 - DBCP返回已关闭的连接

Try to turn on the logging for the driver by following the link - https://msdn.microsoft.com/en-us/library/ms378517(v=SQL.110).aspx 尝试通过以下链接打开驱动程序的日志记录 - https://msdn.microsoft.com/en-us/library/ms378517(v=SQL.110).aspx

Use the finest level logging and check if you can get the details of the problem. 使用最精细级别的日志记录并检查是否可以获取问题的详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 对等方重置HttpClient连接:套接字写入错误 - HttpClient Connection reset by peer: socket write error 对等方重置连接:套接字写入错误 docker - Connection reset by peer: socket write error docker Java - 对等方重置连接:套接字写入错误 - Java - Connection reset by peer: socket write error 使用tomcat7-maven-plugin的Tomcat部署失败,并显示错误“无法调用Tomcat管理器:对等重置连接:套接字写入错误” - Tomcat deploy using tomcat7-maven-plugin fails with error “Cannot invoke Tomcat manager: Connection reset by peer: socket write error” 获取 org.hibernate.util.JDBCExceptionReporter: Connection reset by peer: socket write error - Getting org.hibernate.util.JDBCExceptionReporter: Connection reset by peer: socket write error jmeter中的peer.socket写错误重置连接 - Connection reset by peer.socket write error in jmeter 对等方重置连接:套接字写入错误C ++-Java - Connection reset by peer: socket write error c++ - java 对等方重置连接:Java 中的套接字写入错误,用于文件传输程序 - Connection reset by peer: socket write error in java for file transfer program 对等方重置连接:套接字写入错误在尝试发送对象时 - Connection reset by peer: socket write error While tring to send object 对等方重置连接:套接字写入错误httpclient和geoserver - Connection reset by peer: socket write error httpclient and geoserver
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM