java.lang.NoClassDefFoundError: com/mysql/jdbc/ParameterBindings - grails

I am seeing this error after the server run for more than one day. There is no error when server starts.
org.springframework.jms.listener.adapter.ListenerExecutionFailedException: Listener method 'onMessage' threw exception; nested exception is java.lang.NoClassDefFoundError: com/mysql/jdbc/ParameterBindings
at grails.plugin.jms.listener.adapter.PersistenceContextAwareListenerAdapter.invokeListenerMethod(PersistenceContextAwareListenerAdapter.groovy:44)
at grails.plugin.jms.listener.adapter.LoggingListenerAdapter.onMessage(LoggingListenerAdapter.groovy:48)
at grails.plugin.jms.listener.adapter.PersistenceContextAwareListenerAdapter.onMessage(PersistenceContextAwareListenerAdapter.groovy:33)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: com/mysql/jdbc/ParameterBindings
at com.mysql.jdbc.ConnectionImpl.clientPrepareStatement(ConnectionImpl.java:1450)
at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4165)
at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4069)

This issue could be due to database inactivity. The following setting might help you to keep the database connectivity active, in case there are none, for a long period of time:
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
validationQuery = "SELECT 1"
validationQueryTimeout = 3
validationInterval = 15000
testOnBorrow = true
autoReconnect=true
testWhileIdle = true

Related

Error failed to fetch an image or build from source: error building: failed to solve with frontend docker

I am trying to deploy my website from heroku to fly.io
and when I did fly deploy I got this error
Error failed to fetch an image or build from source: error building: failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: rpc error: code = Unknown desc = quay.io/evl.ms/fullstaq-ruby:2.6.1-jemalloc-slim: not found
fly.toml file
# fly.toml file generated for ancient-tree-3915 on 2022-09-22T15:00:52-07:00
app = "ancient-tree-3915"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[build]
[build.args]
BUILD_COMMAND = "bin/rails fly:build"
SERVER_COMMAND = "bin/rails fly:server"
[deploy]
release_command = "bin/rails fly:release"
[env]
PORT = "8080"
[experimental]
allowed_public_ports = []
auto_rollback = true
[[services]]
http_checks = []
internal_port = 8080
processes = ["app"]
protocol = "tcp"
script_checks = []
[services.concurrency]
hard_limit = 25
soft_limit = 20
type = "connections"
[[services.ports]]
force_https = true
handlers = ["http"]
port = 80
[[services.ports]]
handlers = ["tls", "http"]
port = 443
[[services.tcp_checks]]
grace_period = "1s"
interval = "15s"
restart_limit = 0
timeout = "2s"
[[statics]]
guest_path = "/app/public"
url_prefix = "/"
any idea how to solve it?
This quay.io/evl.ms/fullstaq-ruby:2.6.1-jemalloc-slim image (probably used in you Dockerfile's FROM clause) doesn't really exist. Check it yourself here:
So, the lowest available 2.6.x tag on quay.io is 2.6.3-jemalloc-stretch-slim. Probably, they just purged old, unsupported versions.
Try to upgrade to a newer version.

Grails 4.0.3 Multiple Datasources - Second datasource not available in service

I've followed the instructions/example in the Grails Doc (https://docs.grails.org/4.0.3/guide/conf.html#multipleDatasources) and it still uses the default dataSource.
My application.yml contains:
dataSource:
pooled: true
jmxExport: true
dbCreate: validate
url: jdbc:oracle:thin:#XXX.XX.X.XXX:XXXX:TEST
username: username1
password: password1
driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1 FROM DUAL
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED
dataSources:
identityDb:
url: jdbc:oracle:thin:#YYY.YY.YY.YYY:YYYYY:IDENT
username: username2
password: password2
And my service is defined as follows:
class PictureService {
def grailsApplication
def assetResourceLocator
static dataSource = "identityDb"
def getPictures( identifications ) {
// Loop through all ids
for( i in identifications ) {
//try {
Sql sql = Sql.newInstance( dataSource )
...
It throws this stack dump:
ORA-00942: table or view does not exist
. Stacktrace follows:
java.lang.reflect.InvocationTargetException: null
at org.grails.core.DefaultGrailsControllerClass$ReflectionInvoker.invoke(DefaultGrailsControllerClass.java:211)
at org.grails.core.DefaultGrailsControllerClass.invoke(DefaultGrailsControllerClass.java:188)
at org.grails.web.mapping.mvc.UrlMappingsInfoHandlerAdapter.handle(UrlMappingsInfoHandlerAdapter.groovy:90)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
at org.grails.web.filters.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:67)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: ORA-00942: table or view does not exist
When I dump out the connection string information for dataSource, I can see that it's the first datasource listed and not the identityDb datasource. I'm not using domain classes or GORM and am just writing the SQL directly. Any help with this would be appreciated!
Edit / Update
I changed my service to the following and it's working correctly now. I thought I had tried this before but I must not have gotten the correct combination of things in place.
Note that the application.yml did not change.
class PictureService {
def grailsApplication
def assetResourceLocator
def dataSource_identityDb
def getPictures( identifications ) {
// Loop through all ids
for( i in identifications ) {
try {
Sql sql = Sql.newInstance( dataSource_identityDb )
...
Also, this is different that what is listed in the official docs for using a second datasource in Grails 4.0.3.

grails oracle connection timeout

I have below datasource config in grails.
dataSource_staging_oracle {
dbCreate = "none"
pooled = true
url = "jdbc:oracle:thin:#//my-box-oracle.com:1521/DB1"
driverClassName = "oracle.jdbc.OracleDriver"
username = "USER_1"
password = "encryptedpassword"
passwordEncryptionCodec = PropertiesCodec
}
dataSource_prod_oracle {
dbCreate = "none"
pooled = true
autoReconnect = true
url = "jdbc:oracle:thin:#//my-oracle-prod-box.com:1521/DB2"
driverClassName = "oracle.jdbc.OracleDriver"
username = "user_2"
password = "encrypted_password"
passwordEncryptionCodec = PropertiesCodec
}
Application is able to fetch the DB connection and work fine. However after 1-2 hours of processing, I see connection closed exceptions.
ERROR util.JDBCExceptionReporter - Closed Connection
I believe this has to do with datasource config properties. What grails settings help me in refreshing the connections? I already have set autoReconnect and pooled to true
I use grails 2.3.3
Datasource properties will inform the database what the middleware server will expect from the Database. If your Oracle server does not agree with the settings Grails would like to use, expect sometimes cryptic error messages.
Using pooled connections tells Oracle to hold a number of connections open for the application. If the application is running 1-2 hours and continuously processing, I expect the pool may be running out of valid connections. For some background please view the links included below.
Check out the Grails configuration docs, section 4.4, to see advanced datasource configuration options. Do you have a validation query defined? (eg select 1 from dual;)
Check out this AskTom post for a clear explanation of connection pooling.
Previous StackOverflow question with MySQL but similar error.
Below config helped me fix my problem.
dataSource_staging {
dbCreate = "none"
pooled = true
autoReconnect = true
url = "jdbc:oracle:thin:#//my-box-oracle.com:1521/DB1"
driverClassName = "oracle.jdbc.OracleDriver"
username = "USER_1"
password = "encryptedpassword"
passwordEncryptionCodec = PropertiesCodec
properties {
validationQuery = "SELECT 1 FROM DUAL"
testOnBorrow = true
testWhileIdle = true
testOnReturn = false
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
maxAge = 10 * 60000
maxWait = 10000
maxIdle = 25
maxActive = 50
initialSize = 5
}
}

Grails maxRows/queryTimeout warning

I seem to randomly get the warning below in my Grails 2.2.4 application. It doesn't look like it is causing any issues, but it is still concerning.
I tried to prevent this warning by modifying my datasource properties in my DataSource.groovy file:
dataSource {
pooled = true
properties {
maxWait = 10000 // 10 seconds
minEvictableIdleTimeMillis = 1000 * 60 * 30 // 30 minutes
numTestsPerEvictionRun = 3
testOnBorrow = true
testOnReturn = false
testWhileIdle = false
timeBetweenEvictionRunsMillis = 1000 * 60 * 30 // 30 minutes
validationQuery = "SELECT 1"
}
}
And when that didn't work I tried to set the properties in my BootStrap.groovy file:
def init = { servletContext ->
def ctx = Holders.getApplicationContext()
def dataSource = ctx.dataSourceUnproxied
println "configuring database connection pool"
dataSource.setMinEvictableIdleTimeMillis(1000 * 60 * 30)
dataSource.setTimeBetweenEvictionRunsMillis(1000 * 60 * 30)
dataSource.setNumTestsPerEvictionRun(3)
dataSource.setTestOnBorrow(true)
dataSource.setTestWhileIdle(false)
dataSource.setTestOnReturn(false)
dataSource.setValidationQuery("SELECT 1")
}
Neither attempt prevents the warning. The author of this post said he had success setting the properties directly in the tomcat config, but I need a more generic solution that will work from the command line and in other servers.
2013-09-25 15:07:51,027 [http-bio-8080-exec-9] WARN jdbc.AbstractBatcher - exception clearing maxRows/queryTimeout
java.sql.SQLException: org.apache.commons.dbcp.DelegatingPreparedStatement with address: "com.mysql.jdbc.JDBC4PreparedStatement#13ed0db0: EXCEPTION: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after statement closed." is closed.
at org.apache.commons.dbcp.DelegatingStatement.checkOpen(DelegatingStatement.java:137)
at org.apache.commons.dbcp.DelegatingStatement.getMaxRows(DelegatingStatement.java:237)
at ace_2.DefsUploadController.upload(DefsUploadController.groovy:16)
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
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:724)
After connections to my MySQL database timed out I would see that exact exception as well. I updated the DataSource configuration using the suggestion in the Grails docs as a guideline and I have yet to see any exceptions from closed connections.
Here are my current settings:
properties {
initialSize=5
maxActive=50
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
}

Connection Pooling in Grails 2.2.x?

I could not find how connection pooling is activated in Grails.
In my DataSource.groovy I have the following:
url = "jdbc:mysql://localhost/myapp?useUnicode=yes&characterEncoding=UTF-8"
username = "root"
password = ""
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
pooled = true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery = "select 1"
}
Is there something else I have to do to activate connection pooling than setting pooled = true?
No, the pooled attribute configures pooling. If it's set to false then you will create a new connection each time, and this can take hundreds of milliseconds, so it's not advised.
You would set pooled = false when using JNDI however, since the JNDI datasource does its own pooling, so there's no need to pool twice.
Below is a sample from Grails DataSource documentation page:
dataSource {
pooled = true
dbCreate = "update"
url = "jdbc:mysql://localhost:3306/my_database"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
username = "username"
password = "password"
properties {
jmxEnabled = true
initialSize = 5
maxActive = 50
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
}}
In addition to setting pooled to true, you can also tweak settings on how many connections are initialized up front (initialSize) and the maximum number of connections you would want to maintain when the load gets higher (maxActive).

Resources