本文介绍了Grails应用程序中断管道异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jdk 1.7和MySQL Workbench 6.3在Grails 2.4.4上开发了一个应用程序。它工作了一段时间,但在部署几个小时后,我尝试登录,它停止工作,并抛出异常java.net.SocketException:Broken pipe。

  到 hosts.allow  / code>文件夹。



大多数属性是在另一个线程中进行了一些研究之后添加的但它仍然不起作用。
任何人都可以帮我找到解决这个问题的解决方案吗?

编辑

在尝试Dipak Thoke给出的解决方案后,它仍会抛出破损的管道异常。它还显示以下错误:

  2016-10-25 09:03:33,683 [http-nio-8080-exec-37 ]错误spi.SqlExceptionHelper  - 从服务器成功接收到的最后一个数据包是38,766,997毫秒前。成功发送到服务器的最后一个数据包是38,766,997毫秒前。比服务器配置的'wait_timeout'值长。在应用程序中使用之前,应考虑过期和/或测试连接有效性,增加服务器配置的客户端超时值,或者使用Connector / J连接属性'autoReconnect = true'来避免此问题。 

我应该改变wait_timeout的值吗?因为我已经有了autoReconnect = true属性

解决方案

管道异常。我创建了一个每小时运行一次脚本的web服务,这样应用程序就不会失去与数据库的连接。从那以后,这个例外再也没有被抛出。无论如何,谢谢大家的回答:)

I developed an application on Grails 2.4.4 using jdk 1.7 and MySQL Workbench 6.3. It works for some time, but after some hours of the deployment i try to log in, it stops working and throws the exception "java.net.SocketException: Broken pipe".

2016-10-24 09:40:53,599 [http-nio-8080-exec-12] ERROR errors.GrailsExceptionResolver  - SocketException occurred when processing request: [POST] /login/autenticacao
Broken pipe. Stacktrace follows:
java.net.SocketException: Broken pipe
    at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
    at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
    at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
    at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:140)
    at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3832)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2471)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2651)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2734)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
    at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2322)
    at org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2.doCall(GormStaticApi.groovy:102)
    at sig.PasswordEncrypt.verificaAutenticacao(PasswordEncrypt.groovy:25)
    at sig.LoginController$_closure1.doCall(LoginController.groovy:20)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:198)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

I have an external file with the following configurations:

   beans{
    dataSource(BasicDataSource) {
        url = "jdbc:mysql://127.0.0.1/db_name?autoReconnect=true"
        username = "root"
        password = "root"
        pooled = true
        properties {
            jmxEnabled = true
            initialSize = 5
            maxActive = 50
            maxAge = 10 * 60000
            jdbcInterceptors = "ConnectionState"
            validationInterval = 15000
            minIdle = 5
            maxIdle = 25
            maxWaitMillis = 0
            timeBetweenEvictionRunsMillis = 1000 * 60 * 30
            numTestsPerEvictionRun = 3
            minEvictableIdleTimeMillis = 1000 * 60 * 30
            validationQuery = "SELECT 1"
            validationQueryTimeout = 3
            testOnBorrow = true
            testWhileIdle = true
            testOnReturn = true
            defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
        }
    }
}

I also added port:3306to my.cnf file and mysqld : ALL : ACCEPT to hosts.allow file on /etc folder.

Most of the properties were added after some research in another threads but it still doesnt work.Can anyone help me find a solution to solve this issue?

EDIT

After trying the solution given by Dipak Thoke it still throws the broken pipe exception. It also shows the following error

2016-10-25 09:03:33,683 [http-nio-8080-exec-37] ERROR spi.SqlExceptionHelper  - The last packet successfully received from the server was 38,766,997 milliseconds ago.  The last packet sent successfully to the server was 38,766,997 milliseconds ago. 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.

Should i change the "wait_timeout" value? Cause i already have the "autoReconnect=true" property

解决方案

With the solutions that were presented here my application was always getting a broken pipe exception. I created a webservice with a script the runs every hour, that way the application never loses its connection to the database. Since then the exception was never been thrown again. Thank you all for your answers anyway :)

这篇关于Grails应用程序中断管道异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 03:13