2015-07-28 3 views
12

Я развернул приложение Grails 2.2.1 на удаленный сервер. Через несколько часов, когда я получить доступ к домашней странице приложения, я вижу следующее исключение:Исключенное прерывание трубы с MySql в приложении Grails

Error 500: Internal Server Error 

URI 
    /DocGemStudioZoccali/ 
Class 
    java.net.SocketException 
Message 
    Broken pipe 

Trace 

    Line | Method 
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 

Caused by GroovyPagesException: Error processing GroovyPageView: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query 
->> 631 | runWorker in /index.gsp 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

Caused by DataAccessResourceFailureException: could not execute query; nested exception is org.hibernate.exception.JDBCConnectionException: could not execute query 
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|  25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1 
|  38 | run . . . in gsp_docGemStudioZoccaliindex_gsp 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run  in java.lang.Thread 

Caused by JDBCConnectionException: could not execute query 
->> 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|  25 | doCall in gsp_docGemStudioZoccaliindex_gsp$_run_closure1 
|  38 | run . . . in gsp_docGemStudioZoccaliindex_gsp 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run  in java.lang.Thread 

Caused by CommunicationsException: The last packet successfully received from the server was 138,684,859 milliseconds ago. The last packet sent successfully to the server was 138,684,859 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. 
->> 411 | handleNewInstance in com.mysql.jdbc.Util 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 1116 | createCommunicationsException in com.mysql.jdbc.SQLError 
| 3851 | send . . in com.mysql.jdbc.MysqlIO 
| 2471 | sendCommand in  '' 
| 2651 | sqlQueryDirect in  '' 
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl 
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement 
| 2310 | executeQuery in  '' 
|  96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement 
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2 
|  25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1 
|  38 | run  in gsp_docGemStudioZoccaliindex_gsp 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 

Caused by SocketException: Broken pipe 
->> 109 | socketWrite in java.net.SocketOutputStream 
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
| 153 | write  in  '' 
|  82 | flushBuffer in java.io.BufferedOutputStream 
| 140 | flush  in  '' 
| 3832 | send . . in com.mysql.jdbc.MysqlIO 
| 2471 | sendCommand in  '' 
| 2651 | sqlQueryDirect in  '' 
| 2683 | execSQL in com.mysql.jdbc.ConnectionImpl 
| 2144 | executeInternal in com.mysql.jdbc.PreparedStatement 
| 2310 | executeQuery in  '' 
|  96 | executeQuery in org.apache.commons.dbcp.DelegatingPreparedStatement 
| 108 | doCall in org.grails.datastore.gorm.GormStaticApi$_methodMissing_closure2 
|  25 | doCall . in gsp_docGemStudioZoccaliindex_gsp$_run_closure1 
|  38 | run  in gsp_docGemStudioZoccaliindex_gsp 
| 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor 
| 615 | run  in java.util.concurrent.ThreadPoolExecutor$Worker 
^ 722 | run . . . in java.lang.Thread 

Я попытался решить эту проблему, как видно на другой вопрос в SO, но он не работает меня.

Вот что я сделал в конфигурационном файле:

dataSource { 
     dbCreate = "update" 
     url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8" 
     username = "root" 
     password = "root" 
     //run the evictor every 30 minutes and evict any connections older than 30 minutes. 
     minEvictableIdleTimeMillis=1800000 
     timeBetweenEvictionRunsMillis=1800000 
     numTestsPerEvictionRun=3 
     //test the connection while its idle, before borrow and return it 
     testOnBorrow=true 
     testWhileIdle=true 
     testOnReturn=true 
     validationQuery="SELECT 1" 
    } 

Обратите внимание, что, если я обновить страницу, все работает правильно. Кто-нибудь знает что-то, чтобы решить эту проблему?

EDIT 1:

Я редактировал my.cnf файл в /etc папку, добавив следующее:

wait_timeout = 28800 
interactive_timeout = 28800 

, но ничего не меняется

EDIT 2:

Это фактические данные sourc е, что я использую. Сломанная труба все еще появляется

dataSource { 
    dbCreate = "update" 
    url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true" 
    username = "root" 
    password = "root" 
    minIdle = 5 
    maxIdle = 25 
    maxWait = 10000 
    maxAge = 10 * 60000 
    timeBetweenEvictionRunsMillis = 5000 
    minEvictableIdleTimeMillis = 60000 
    validationQuery = "SELECT 1" 
    validationQueryTimeout = 3 
    validationInterval = 15000 
    testOnBorrow = true 
    testWhileIdle = true 
    testOnReturn = false 
    jdbcInterceptors = "ConnectionState;StatementCache(max=200)" 
    defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED 
} 

EDIT 3:

Вот StackTrace после предложения данного Джеймсом Kleeh

2015-12-04 17:41:36,924 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:722) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
2015-12-04 17:41:36,931 [http-bio-8080-exec-63] ERROR context.GrailsContextLoader - Error initializing Grails: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:722) 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Cannot resolve reference to bean 'dataSourceUnproxied' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSourceUnproxied': Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Caused by: org.springframework.beans.NotWritablePropertyException: Invalid property 'maxAge' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'maxAge' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter? 
     ... 3 more 
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Error listenerStart 
Dec 04, 2015 5:41:36 PM org.apache.catalina.core.StandardContext startInternal 
SEVERE: Context [/DocGemStudioTest] startup failed due to previous errors 
2015-12-04 17:41:36,955 [http-bio-8080-exec-63] WARN lifecycle.ShutdownOperations - Error occurred running shutdown operation: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext 
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
     at java.lang.Thread.run(Thread.java:722) 
Dec 04, 2015 5:41:36 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc 
SEVERE: The web application [/DocGemStudioTest] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered. 

EDIT 4:

Я отредактировал блок properties, и теперь приложение запускается. Мне нужно проверить, возникает ли ошибка через несколько часов.

properties{ 
       minIdle = 5 
       maxIdle = 25 
       maxWait = 10000 

       timeBetweenEvictionRunsMillis = 5000 
       minEvictableIdleTimeMillis = 60000 
       validationQuery = "SELECT 1" 
       validationQueryTimeout = 3 

       testOnBorrow = true 
       testWhileIdle = true 
       testOnReturn = false 

       defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED 
     } 
+0

ли вы намеренно оставить в «urlofapp/myappname?» в вашем источнике данныхSource, чтобы скрыть это для этого вопроса? Или это проблема вырезания и вставки? – dspano

+0

Я использую только «urlofapp/myappname» вместо настоящих имен только для вопроса, очевидно – FrancescoDS

+0

Ваш экземпляр mysql принимает соединения с удаленного сервера? вы изменили настройки по умолчанию? –

ответ

-2

кажется мне, как MySQL является таймаут это подключение к вы. Наверное, вы не можете это сделать.

Можете ли вы рассмотреть возможность закрытия соединения, если на нем нет трафика, а затем снова открыть его, когда он понадобится снова?

+0

Что вы имеете в виду с «вы»? Вы имеете в виду, что это невозможно решить по-другому? – FrancescoDS

+0

Я говорю, что похоже, что тайм-аут происходит на стороне MySQL соединения. Если вы не контролируете конфигурацию MySQL, может быть мало что можно сделать по этому поводу, что изменит ваш подход к тому, как * вы * обрабатываете соединение. Это, по сути, тот же ответ, что и стеникс, датированный 4 декабря '15. –

1

Так что я считаю, все, кроме dbCreate, url, username и password потребности быть в свойствах блока:

dataSource { 
    dbCreate = "update" 
    url = "jdbc:mysql://urlofapp/myappname?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true" 
    username = "root" 
    password = "root" 
    properties { 
     minIdle = 5 
     maxIdle = 25 
     maxWait = 10000 
     maxAge = 10 * 60000 
     timeBetweenEvictionRunsMillis = 5000 
     minEvictableIdleTimeMillis = 60000 
     validationQuery = "SELECT 1" 
     validationQueryTimeout = 3 
     validationInterval = 15000 
     testOnBorrow = true 
     testWhileIdle = true 
     testOnReturn = false 
     jdbcInterceptors = "ConnectionState;StatementCache(max=200)" 
     defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED 
    } 
} 
+0

Я стараюсь, и я дам вам знать. – FrancescoDS

+0

Добавление блока свойств, приложение не запускается – FrancescoDS

+0

Это должен быть правильный ответ. Вы получаете сообщение об ошибке, когда оно не запускается? ValidateionQuery - это свойства, которые делают трюк, чтобы поддерживать сеанс. – stenix

1

Хотя, это должно быть странно, но если приложение Grails и сервер MySQL оба на той же машине, а затем использовать localhost или 127.0.0. вместо реального IP-адреса xxx.xxx.xxx.xxx

dataSource { 
    dbCreate = "update" 
    url = "jdbc:mysql://localhost:3306/docgem_test_db?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true" 
    // Your other properties 
} 
+0

@FrancescoDS Я не сразу понял, что вы сами автор вопроса, пытающегося удалить свой IP-адрес из сообщения, но позже я принял ваше редактирование. Но я просто хочу предупредить вас, что ваш реальный IP-адрес по-прежнему отображается в истории редактирования моего ответа, поэтому подумайте над добавлением дополнительной безопасности, если ваш IP-адрес имеет ваше производственное приложение или попытается по возможности изменить его. (Я тоже удалю этот комментарий). –

0

Пожалуйста, попробуйте ниже не добавление driverClassName и dialect, и я также добавил pooled в случае, если вам нужно что

dataSource { 
    pooled = true 
    driverClassName = "com.mysql.jdbc.Driver" 
    dialect = "org.hibernate.dialect.MySQL5InnoDBDialect" 
    dbCreate = "update" 
    url = "jdbc:mysql://urlofapp/myappname? useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true" 
    username = "root" 
    password = "root" 
    properties { 
     minIdle = 5 
     maxIdle = 25 
     maxWait = 10000 
     maxAge = 10 * 60000 
     timeBetweenEvictionRunsMillis = 5000 
     minEvictableIdleTimeMillis = 60000 
     validationQuery = "SELECT 1" 
     validationQueryTimeout = 3 
     validationInterval = 15000 
     testOnBorrow = true 
     testWhileIdle = true 
     testOnReturn = false 
     jdbcInterceptors = "ConnectionState;StatementCache(max=200)" 
     defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED 
} 

}