开发者社区> 问答> 正文

关于使用Druid,web项目停一段时间再访问会报错 socket write error?报错

@wenshao 您好,想跟你请教个问题:

web项目停一段时间再访问会报错:

Caused by: java.net.SocketException: Connection reset by peer: socket write error

报了错,再访问就正常了。

我怀疑是validationQuery根本没有定时执行,我检查配置都没问题,这块有什么特殊配置?

项目使用的是 spring注入+jdbctemplate.

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init"
        destroy-method="close">
        <property name="url" value="**" />
        <property name="username" value="**" />
        <property name="password" value="**" />

        <property name="filters" value="stat" />

        <property name="maxActive" value="100" />
        <property name="initialSize" value="1" />
        <property name="maxWait" value="60000" />
        <property name="minIdle" value="1" />

        <property name="timeBetweenEvictionRunsMillis" value="60000" />
        <property name="minEvictableIdleTimeMillis" value="300000" />

        <property name="validationQuery" value="SELECT 'x' FROM DUAL" />
        <property name="validationQueryTimeout" value="30000" />
        

        <property name="testWhileIdle" value="true" />
        <property name="testOnBorrow" value="false" />
        <property name="testOnReturn" value="false" />

        <property name="poolPreparedStatements" value="true" />
        <property name="maxPoolPreparedStatementPerConnectionSize" value="50" />
    </bean>


展开
收起
爱吃鱼的程序员 2020-06-14 22:08:30 1124 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    能把堆栈信息提供出来么?谢谢,看我的补充<preclass="brush:java;toolbar:true;auto-links:false;">[16:15:03][http--8080-16]ERROR[com.alibaba.druid.util.JdbcUtils:84]-closeconnectionerrorjava.sql.SQLRecoverableException:IO错误:Connectionresetbypeer:socketwriteerroratoracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:770)atoracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:4581)atcom.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:169)atcom.alibaba.druid.filter.stat.StatFilter.connection_close(StatFilter.java:254)atcom.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:165)atcom.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.close(ConnectionProxyImpl.java:115)atcom.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:82)atcom.alibaba.druid.pool.DruidDataSource.discardConnection(DruidDataSource.java:969)atcom.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:936)atcom.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)atcom.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)atcom.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:882)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:874)atcom.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)atorg.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)atorg.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)atorg.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:388)atorg.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:468)atorg.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:478)atorg.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:488)atorg.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:494)atcom.test.web.db.JdbcBase.count(JdbcBase.java:553)atcom.test.web.dao.privilege.RoleDao.getRoleList(RoleDao.java:88)atcom.test.web.controller.privilege.RoleController.role_list(RoleController.java:44)atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource)atjava.lang.reflect.Method.invoke(UnknownSource)atorg.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)atorg.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)atorg.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)atorg.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)atorg.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)atorg.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)atorg.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)atorg.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)atorg.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:114)atorg.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)atjavax.servlet.http.HttpServlet.service(HttpServlet.java:91)atcom.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)atorg.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)atorg.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)atcom.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)atcom.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)atcom.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:266)atcom.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)atcom.caucho.server.port.TcpConnection.run(TcpConnection.java:678)atcom.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)atcom.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)atjava.lang.Thread.run(UnknownSource)Causedby:java.net.SocketException:Connectionresetbypeer:socketwriteerroratjava.net.SocketOutputStream.socketWrite0(NativeMethod)atjava.net.SocketOutputStream.socketWrite(UnknownSource)atjava.net.SocketOutputStream.write(UnknownSource)atoracle.net.ns.DataPacket.send(DataPacket.java:209)atoracle.net.ns.NetOutputStream.flush(NetOutputStream.java:215)atoracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:302)atoracle.net.ns.NetInputStream.read(NetInputStream.java:249)atoracle.net.ns.NetInputStream.read(NetInputStream.java:171)atoracle.net.ns.NetInputStream.read(NetInputStream.java:89)atoracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)atoracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)atoracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:426)atoracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:390)atoracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)atoracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:59)atoracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:757)...52more



    请问你的问题解决了吗,我也遇到了这个问题,请问你是怎么解决的?没有<spanstyle="font-size:13.3333330154419px;">oracle忽悠这个bug,mysql没问题,我两年以前就反馈过的,但是一直没有结果最后解决了吗?我是用mysql5.6,也是遇到類似的問題,druid(version0.2.26)testWhileIdle,testOnBorrow和validationQuery也都設定了,都沒有效,還有什麼招嗎?

    好像大家都是Oracle连接的时候出问题,Mysql连接的时候却没有问题,我也遇到这个问题了,按理来说设置了validationQuery应该可以解决的,时间上并没有什么卵用~打算换个连接池试试了。

    可以看下这个<atarget="_blank"rel="nofollow">https://github.com/alibaba/druid/issues/591

    这个后来有找到解决方案嘛?

    回复<aclass="referer"target="_blank">@Andyfoo:您那边使用的也是Oracle吗现在用的新版没有问题

    找到一个解决方案,可以试试

    2020-06-14 22:08:46
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载