connection closed error in heroku cleardb addon - grails

i just got deploying a very simple grails app in heroku using cleardb addon, everything is fine until past some minutes and when i try to get view that has access to database i get and error message.
Here i paste a snippet from heroku logs
2014-06-04T20:12:17.511251+00:00 app[web.1]: 2014-06-04 20:12:17,511 [http-nio-38536-exec-1] ERROR util.JDBCExceptionReporter - No operations allowed after
connection closed.
2014-06-04T20:12:17.515181+00:00 app[web.1]: 2014-06-04 20:12:17,514 [http-nio-38536-exec-1] ERROR errors.GrailsExceptionResolver - EOFException occurred when processing request: [GET] /user
2014-06-04T20:12:17.515187+00:00 app[web.1]: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.. Stacktrace follows:
2014-06-04T20:12:17.515190+00:00 app[web.1]: at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:3166)
2014-06-04T20:12:17.515188+00:00 app[web.1]: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.
And here is my datasource production section
production {
dataSource {
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
uri = new URI(System.env.CLEARDB_DATABASE_URL?:"//bb2c98a68a13fe:3a6fd398#us-cdbr-east-06.cleardb.net/heroku_b28cc03a245469f?reconnect=true")
url = "jdbc:mysql://"+uri.host+uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
}
}
The log tell me about connection closed. i do not know what to do from here, i hope you can help me, thanks for your time

I finally got a solution to this problem, thanks for the help from heroku support team and cleardb support team, the solution was to add properties to datasource into production environment, the final code in datasource.groovy
production {
dataSource {
dbCreate = "update"
driverClassName = "com.mysql.jdbc.Driver"
dialect = org.hibernate.dialect.MySQL5InnoDBDialect
uri = new URI(System.env.CLEARDB_DATABASE_URL?:"//bb2c98a68a13fe:3a6fd398#us-cdbr-east-06.cleardb.net/heroku_b28cc03a245469f?reconnect=true")
url = "jdbc:mysql://"+uri.host+uri.path
username = uri.userInfo.split(":")[0]
password = uri.userInfo.split(":")[1]
properties {
// See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
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"
defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
}
}
}
this are the default values just do not delete it as i did it.
the reason why is this necessary is in cleardb team support answer, i paste next
6/05/2014 03:07PM wrote
Hello,
My suspicion - without troubleshooting further, just a first pass - is
that your app is not managing connections properly. Your current
database service tier allows a maximum of 4 simultaneous connections
to the db. It is likely that your application is trying to open more
connections than are allowed.
If you are using connection pooling, you must make sure that your pool
is set to no larger than 4 total (and that's across all dynos if you
have more than 1).
Heroku's networking times out idle connections at 60 seconds, so your
database connector must be set either to have an idle timeout of no
more than 60 seconds, or you must have a keep-alive interval of less
than 60 (which sends a trivial query such as "SELECT 1" to keep the
connection active).
We do not support grails directly, so I unfortunately can't give you
specific directions of how to do that within this framework.
I hope this is helpful.
Mike ClearDB Support Team
I hope it help to someone

Related

Is play-mailer an smtp server

I need the functionality to send emails from my Play 2.6.x server. I found that I could use play-mailer (https://github.com/playframework/play-mailer#usage)
Question 1 - Do I need a separate smtp server or is play-mailer an smtp server itself.
Question 2 - At the moment, I am running the application on localhost but I'll eventually deploy it. Would my application work if I just use localhost in the configuration below?
play.mailer {
host = localhost // (mandatory)
port = 25 // (defaults to 25)
ssl = no // (defaults to no)
tls = no // (defaults to no)
tlsRequired = no // (defaults to no)
user = null // (optional)
password = null // (optional)
debug = no // (defaults to no, to take effect you also need to set the log level to "DEBUG" for the application logger)
timeout = null // (defaults to 60s in milliseconds)
connectiontimeout = null // (defaults to 60s in milliseconds)
mock = true// (defaults to no, will only log all the email properties instead of sending an email)
}
Question 3 - Once I deploy the application in the cloud (say AWS), do I just need to change host in the above configuration to make it work?
Question 4 - I am suppose to pass username and password in the play.mailer config. Considering that I version-control my application.conf, is it safe to enter the username and password in the file?
Answer 1:
You will need an smtp server for play.mailer to connect to. This is generally what you'll put in your host in production.
Answer 2:
Yes it should work just like that, I think you'll have to set mock = yes though.
Answer 3:
If you decide to use aws (https://aws.amazon.com/ses/), your conf will look something like this.
play.mailer {
host = "email-smtp.us-east-1.amazonaws.com" // (mandatory) - url from amazon
port = 465 // (defaults to 25)
ssl = yes // (defaults to no)
tls = no // (defaults to no)
tlsRequired = no // (defaults to no)
user = "id_from_amazon"
password = "password_from_amazon"
debug = no // (defaults to no)
timeout = null // (defaults to 60s in milliseconds)
connectiontimeout = null // (defaults to 60s in milliseconds)
mock = no // for actually sending emails. set it to yes if you want to mock.
}
Answer 4:
So the security aspect depends on what environment you're using your play server in. If application.conf is likely to be seen by somebody then you could use environment variables instead of writing it in the application.conf
password = ${APP_MAILER_PASSWORD}
and then set APP_MAILER_PASSWORD as an environment variable. Again, this isn't secure if someone can access the console of your server - but not much is at that point.

Openresty: create connection to Tarantool on init

I want to create connection to Tarantool database in init_by_lua_block or init_worker_by_lua_block and then use that created connection in each content_by_lua_block:
init_by_lua_block {
local tnt = require 'resty.tarantool'
local tar, err = tnt:new({
host = '127.0.0.1',
port = 3312,
user = 'user',
password = 'password',
socket_timeout = 2000
})
local res, err = tar:connect()
}
But cosocket api is disabled in directives init_*_by_lua*. How I can create connection one time instead of creating connections for each request?
Use https://github.com/perusio/lua-resty-tarantool#set_keepalive
Makes the connection created get pushed to a connection pool so that the connection is kept alive across multiple requests.

Get connection pool status with grails

I have a webservice built with grails that connects to a MySQL database. Since i upgraded to 2.4.3 I've had problems with the connectionpool not releasing the connections, resulting in an exception:
org.apache.tomcat.jdbc.pool.PoolExhaustedException: [http-bio-8080-exec-216] Timeout: Pool empty. Unable to fetch a connection in 30 seconds, none available[size:50; busy:50; idle:0; lastwait:30000]
This is my Datasources.groovy
dataSource {
url = "jdbc:mysql://..."
username = "xxx"
password = "xxx"
pooled = true
properties {
maxActive = 50
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
dataSource_survey {
url = "jdbc:mysql://..."
username = "xxx"
password = "xxx"
pooled = true
properties {
maxActive = 50
maxAge = 10 * 60000
timeBetweenEvictionRunsMillis = 5000
minEvictableIdleTimeMillis = 60000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
I've read grails JIRA and some people seem to have similar problems. But I haven't been able to fix it with the information provided there.
Accessing the status of the connectionpool would help debugging a great deal. How can I check the status of the connectionpool to see how many connections are idle/busy during runtime?
The connection pool is registered as a javax.sql.DataSource but that interface only has methods for getting a Connection (one with username/password and one without), accessing a log writer, and getting/setting the login timeout. Everything else is left to the vendor to decide, and there's very little commonality between vendors in their methods for configuring pools initially, and working with and monitoring them throughout the app run.
So you really need to find out which library is used for the pool and use their API. That would ideally be as simple as accessing the dataSource bean (that's easy, just dependency-inject it into a service/controller/etc. like any bean - as a class-scope field, in this case def dataSource) and printing its class name. But we wrap the datasource in a few proxies to add some important behaviors, so it not easy to access
You're in luck though - for cases like this, we leave the original unproxied instance alone and register it as the dataSourceUnproxied bean which you can also dependency-inject (just don't access any of its connections, only information).
For a long time we used commons-pool to manage datasources, but a while back we switched to the Tomcat JDBC Pool because benchmark tests showed that it's faster than any other they looked at (including C3P0), and its configuration methods are based on commons-pool's, so it was basicallly a drop-in replacement with a significant performance boost and more configurability.

Cannot connect to mysql from grails

I am using wamp server, it comes with mysql 5.5.16 and I am trying use the mysql from grails 1.3.7. In my Buildconfig.groovy file i have added "runtime 'mysql:mysql-connector-java:5.1.6'" under dependencies and my datasource.groovy looks like this:
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
username = "root"
password = ""
url = "jdbc:mysql://localhost:3306/moviestore_dev"
}
but when i refresh dependencies or run the app, i get error=>
:: mysql#mysql-connector-java;5.1.6: not found
I can connect to the database but the data in the database remains as long as the app is running, the next time I run the app, all the data are gone !
I have no idea what is happening, please help !
Thanks
problem is in
dbCreate = "create-drop"
use
dbCreate = "update"
• create-drop: Drops and re-creates the database schema on each application load
• create: Creates the database on application load
• update: Creates and/or attempts an update to existing tables on application load
• [blank]: Does nothing

Paypal Sandbox Do Direct Payment Internal Error 10001 Timeout Processing Request

This is in an MVC2 project, so I'm using C# in ASP.
This is what I'm sending to https://api-3t.sandbox.paypal.com/nvp:
VERSION = 65.0
SIGNATURE = AFcWxV21C7fd0v3bYYYRCpSSRl31AxdW2pQp.tWHTjGNcHflR-LJhJ0t
USER = seller_1283487740_biz_api1.gmail.com
PWD = 1283487748
AMOUNT = 50.00
CREDITCARDTYPE = Visa
ACCT = 4031477440127509
EXPDATE = 12/2015
CVV2 =123
IPADDRESS = 127.0.0.1
METHOD = DoDirectPayment
I can GetBalance, I can produce other errors when I intentionally send something wrong, but DoDirectPayment or DoAuthorization returns this:
TIMESTAMP = 2010-12-24T03:35:10Z
CORRELATIONID = 2ca329fdbe3c0
ACK = Failure
L_ERRORCODE0 = 10001
L_SHORTMESSAGE0 = Internal Error
L_LONGMESSAGE0 = Timeout processing request
Why Am I getting this error?
Yeah, I'm getting the same thing. I tested my code on their production URL and it worked just fine.
Given how much they are focused on developers, it's amazing how horrible their API is. I can get points and follow other people on their little social network, x.com, but I CAN'T TELL WHAT THE CURRENT VERSION OF THE API IS!?! (You have to view the source of the webpage and find it embedded in an HTML comment) </rant>
From what I've read around, this can be a sign of malformed data. In my case, I was sending the form as
multipart/form-data
instead of
application/x-www-form-urlencoded
I hadn't read anywhere in the docs about form encoding, but as soon as I changed it the PP server got a lot more friendly.
I believe its Pay Pals defence againest attacks. Theres certain procedures that action in the code
Error codes:
* 100 Access denied
* 105 Order already exists
* 106 DID ID: DID_ID NOT found
* 107 Invalid Protocol
* 108 DID: DIDNUMBER NOT found
* 109 DID: DIDNUMBER in Pending/Remove status
* 110 DID: DIDNUMBER NOT renewed
* 111 Invalid status code. Valid codes: 0 - Disable, 1 - Enable
* 113 Order NOT found for DIDNUMBER
* 114 Order already canceled for DIDNUMBER
* 115 ORDER: Cannot cancel not pending order for DIDNUMBER. Please, use did_cancel
* 120 UNIQ: UNIQUEKEY NOT found
* 121 No cities for this country
* 150 Sandbox error. DIDs max limit reached
* 200 Internal Server Error
Through a Sandbox control panel these error messages are given to a user if the server believes that it is under-attack.

Resources