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

Andyfoo 发布于 2014/08/30 20:21
阅读 8K+
收藏 0

@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>


以下是问题补充:

@Andyfoo:我看代码没有找到定时执行验证sql的,只有一个 boolean com.alibaba.druid.pool.vendor.OracleValidConnectionChecker.isValidConnection(Connection conn, String validateQuery, int validationQueryTimeout) 是在连接时调用,但这时已经断了,所以报错。报错之后就正常了 (2014/08/31 09:35)
加载中
0
wenshao
wenshao
能把堆栈信息提供出来么?
Andyfoo
Andyfoo
谢谢,看我的补充
0
Andyfoo
Andyfoo
[16:15:03] [http--8080-16] ERROR [com.alibaba.druid.util.JdbcUtils:84] - close connection error
java.sql.SQLRecoverableException: IO 错误: Connection reset by peer: socket write error
	at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:770)
	at oracle.jdbc.driver.PhysicalConnection.close(PhysicalConnection.java:4581)
	at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:169)
	at com.alibaba.druid.filter.stat.StatFilter.connection_close(StatFilter.java:254)
	at com.alibaba.druid.filter.FilterChainImpl.connection_close(FilterChainImpl.java:165)
	at com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl.close(ConnectionProxyImpl.java:115)
	at com.alibaba.druid.util.JdbcUtils.close(JdbcUtils.java:82)
	at com.alibaba.druid.pool.DruidDataSource.discardConnection(DruidDataSource.java:969)
	at com.alibaba.druid.pool.DruidDataSource.getConnectionDirect(DruidDataSource.java:936)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4544)
	at com.alibaba.druid.filter.stat.StatFilter.dataSource_getConnection(StatFilter.java:661)
	at com.alibaba.druid.filter.FilterChainImpl.dataSource_connect(FilterChainImpl.java:4540)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:882)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:874)
	at com.alibaba.druid.pool.DruidDataSource.getConnection(DruidDataSource.java:97)
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:388)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:468)
	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:478)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:488)
	at org.springframework.jdbc.core.JdbcTemplate.queryForObject(JdbcTemplate.java:494)
	at com.test.web.db.JdbcBase.count(JdbcBase.java:553)
	at com.test.web.dao.privilege.RoleDao.getRoleList(RoleDao.java:88)
	at com.test.web.controller.privilege.RoleController.role_list(RoleController.java:44)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:852)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
	at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
	at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:87)
	at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:187)
	at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:266)
	at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:270)
	at com.caucho.server.port.TcpConnection.run(TcpConnection.java:678)
	at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:721)
	at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:643)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.net.SocketException: Connection reset by peer: socket write error
	at java.net.SocketOutputStream.socketWrite0(Native Method)
	at java.net.SocketOutputStream.socketWrite(Unknown Source)
	at java.net.SocketOutputStream.write(Unknown Source)
	at oracle.net.ns.DataPacket.send(DataPacket.java:209)
	at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:215)
	at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:302)
	at oracle.net.ns.NetInputStream.read(NetInputStream.java:249)
	at oracle.net.ns.NetInputStream.read(NetInputStream.java:171)
	at oracle.net.ns.NetInputStream.read(NetInputStream.java:89)
	at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
	at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
	at oracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:426)
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:390)
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
	at oracle.jdbc.driver.T4C7Ocommoncall.doOLOGOFF(T4C7Ocommoncall.java:59)
	at oracle.jdbc.driver.T4CConnection.logoff(T4CConnection.java:757)
	... 52 more



0
chenmo_huihui
chenmo_huihui
请问你的问题解决了吗,我也遇到了这个问题,请问你是怎么解决的?
Andyfoo
Andyfoo
没有
0
j
jinyanhui2008
oracle 忽悠这个bug,mysql没问题,我两年以前就反馈过的,但是一直没有结果
0
JMiss
JMiss
我是用mysql5.6,也是遇到類似的問題,druid(version 0.2.26) testWhileIdle,testOnBorrow和validationQuery也都設定了,都沒有效,還有什麼招嗎?
0
你个大胖子
你个大胖子

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

0
不懂风
不懂风

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

Andyfoo
Andyfoo
现在用的新版没有问题
返回顶部
顶部