2014-11-03 88 views
1

我在一机在另一台机器上运行两个Web应用程序和一个DB“同时发送给后端的I/O错误发生”(它们使用相同的DB) 一个可以运行得很好,但另一种。约4小时后总是下降。PostgreSQL的例外:

下面是错误信息:

Error 2014-11-03 13:31:05,902 [http-bio-8080-exec-7] ERROR spi.SqlExceptionHelper - An I/O error occured while sending to the backend. 
| Error 2014-11-03 13:31:05,904 [http-bio-8080-exec-7] ERROR spi.SqlExceptionHelper - This connection has been closed. 

PostgreSQL的日志:

2014-10-26 23:41:31 CDT WARNING: pgstat wait timeout 
2014-10-27 01:13:48 CDT WARNING: pgstat wait timeout 
2014-10-27 03:55:46 CDT LOG: could not receive data from client: Connection timed out 
2014-10-27 03:55:46 CDT LOG: unexpected EOF on client connection 

是谁造成这个问题,应用程序或数据库?或网?

+0

网络连接,很可能是NAT连接跟踪表到期。 – 2014-11-03 13:25:32

回答

1

原因:

在这一点上,很明显,这是闲置的TCP连接已经被打破,但我们的应用程序仍然认为它是开放的。空闲连接是指应用程序暂时未在使用的池中的连接。

一些搜索后,我来到了我的应用程序和数据库之间的网络防火墙在1小时后丢弃空闲/陈旧连接的结论。这似乎是很多人遇到的常见问题。

解决方案:

Grails中,你可以设置这DataSource.groovy中。

environments { 
    development { 
     dataSource { 
      //configure DBCP 
      properties { 
       maxActive = 50 
       maxIdle = 25 
       minIdle = 1 
       initialSize = 1 
       minEvictableIdleTimeMillis = 60000 
       timeBetweenEvictionRunsMillis = 60000 
       numTestsPerEvictionRun = 3 
       maxWait = 10000 

       testOnBorrow = true 
       testWhileIdle = true 
       testOnReturn = false 

       validationQuery = "SELECT 1" 
      } 
     } 
    } 
}