NodeJS - MySQL server not working after some time - mysql

Basically I have my Node.js server working along with MySQL. When I work on my localhost everything's fine. The connection to my local DB (I'm using XAMPPP) is great and nothing breaks.
The problem comes along when the server is hosted by a provider. The one I hired uses cPanel and everithing's great until some time passes, because I get this error:
events.js:377
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/home/adminis6/Artesofa/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:400:28)
at Protocol._delegateError (/home/adminis6/Artesofa/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.handleNetworkError (/home/adminis6/Artesofa/node_modules/mysql/lib/protocol/Protocol.js:371:10)
at Connection._handleNetworkError (/home/adminis6/Artesofa/node_modules/mysql/lib/Connection.js:418:18)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! amor-muebles#1.0.0 start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the amor-muebles#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/adminis6/.npm/_logs/2021-11-30T19_15_37_322Z-debug.log
I've been researching how to solve this problem and the only useful answer I got basically said that the DB connection was timming out, so all I had to do was to make a request on an interval and hope it won't break. So I wrote the following code in my app.js file:
const fetch = require("node-fetch");
setInterval(() => {
fetch('sample-endpoint');
}, 30000);
Although this seemed to have solved my problem, it appeared over and over again (note that the server did last longer being up).
Later on, some people taught me about CRONS so I made the following CRON:
PATH=$PATH:$HOME/bin; export PATH; /usr/bin/pgrep "node" >/dev/null || (cd /home/adminis6/Artesofa/; pkill node; pkill npm; nohup npm start &)
And it does work, because it gets the server up, but it instantly crashes (literally right after the server initiates, even after the server connects to the DB successfully), and it logs the following:
> amor-muebles#1.0.0 start /home/adminis6/Artesofa
> node app.js
Server running on port 3100
mysql connected
events.js:377
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/home/adminis6/Artesofa/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:400:28)
at Protocol._delegateError (/home/adminis6/Artesofa/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.handleNetworkError (/home/adminis6/Artesofa/node_modules/mysql/lib/protocol/Protocol.js:371:10)
at Connection._handleNetworkError (/home/adminis6/Artesofa/node_modules/mysql/lib/Connection.js:418:18)
at Socket.emit (events.js:400:28)
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! amor-muebles#1.0.0 start: `node app.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the amor-muebles#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/adminis6/.npm/_logs/2021-11-30T20_14_02_182Z-debug.log
I don't know what else to try nor I have much more time, please help!
If you need it, here is my app.js:
/* ----------- Server initialization ----------- */
//Here are all the modudule's require
const app = express();
// Connect to mySQL DB
const db = require('./db/connectDB');
// Set server to listen on specified port
app.listen(process.env.PORT || '4000', () => {
console.log(`Server running on port ${process.env.PORT} AAAAA`);
})
app.set('view engine', 'ejs');
app.use(express.static('public'));
app.set('views', [
path.join(__dirname, 'views/adminSite/')
]);
/* ----------- Middleware ----------- */
app.use(express.urlencoded({ extended: true }));
app.use(helmet());
app.use(cookieParser());
app.use(morgan('tiny'));
/* ----------- Routes ----------- */
app.use('/api', apiRoutes);
setInterval(() => {
fetch('https://administracionartesofa.com/api/sucursales');
}, 30000);
And, finally, here is my connectDB file:
const mysql = require('mysql');
const dotenv = require('dotenv').config();
const settings = process.env.ENV === 'dev' ? require('./devSettings.json') : require('./prodSettings.json');
let db;
const connectDatabase = () => {
if (!db) {
db = mysql.createConnection(settings);
db.connect((err) => {
if (err) {
console.log('Database error');
console.log(err);
connectDatabase();
} else {
console.log('mysql connected');
}
})
}
return db;
}
module.exports = connectDatabase();

Use a mysql connection pool in your nodejs program. Your hosting provider's cheap and nasty shared MySql server has an aggressively short idle connection time limit. If you hold open a connection for too long the server slams it shut, so you get ECONNRESET.
Why? Cybercreeps trying to break in to random servers on the internet for fun and profit. This slows them down a bit, hopefully.
Connection pools cope with this behind the scenes if you
set up a pool at app startup, and
grab a connection from the pool when you need one, use it, and then return it to the pool.
Or, you can skip the pooling and just close your connection when you're done using it, then open a new one when you need it again. That will work fine for a low-volume app, but it might cause some inefficient connection thrashing if your volume goes up. Pools are better.

Related

node server in expressjs stops working after a while on its own

after running npm start, some time passes and then i get this error in the terminal. I am new to express js and node paired with mysql, so I can't really understand the errors below, hopefully that's enough context for this. The project is a simple table display of the database's table content, and it works fine, I just have to run npm start every 10-40 seconds.
events.js:291
throw er; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:94:28)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1226:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:314:20)
at Protocol._delegateError (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.end (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:116:8)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:94:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodeapp#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodeapp#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/thodoristhomaidis/.npm/_logs/2021-01-22T03_09_42_711Z-debug.log
thodoristhomaidis#Theos-iMac nodeapp % npm i -g mysql
+ mysql#2.18.1
added 11 packages from 15 contributors in 0.589s
thodoristhomaidis#Theos-iMac nodeapp % npm start
> nodeapp#0.0.0 start /Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp
> node ./bin/www
Database is connected successfully !
GET /users/form 304 7.634 ms - -
GET /css/form-style.css 404 3.291 ms - 1532
events.js:291
throw er; // Unhandled 'error' event
^
Error: Connection lost: The server closed the connection.
at Protocol.end (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:112:13)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:94:28)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:526:10)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1226:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on Connection instance at:
at Connection._handleProtocolError (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:423:8)
at Protocol.emit (events.js:314:20)
at Protocol._delegateError (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:398:10)
at Protocol.end (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/protocol/Protocol.js:116:8)
at Socket.<anonymous> (/Volumes/HDD 500GB/* Documents/2 webdev/projects/nodejs/db connection demo/nodeapp/node_modules/mysql/lib/Connection.js:94:28)
[... lines matching original stack trace ...]
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
fatal: true,
code: 'PROTOCOL_CONNECTION_LOST'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nodeapp#0.0.0 start: `node ./bin/www`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nodeapp#0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/thodoristhomaidis/.npm/_logs/2021-01-22T03_11_13_709Z-debug.log
Try to use this code to handle server disconnect:
var db_config = {
host: 'localhost',
user: 'root',
password: '',
database: 'example'
};
var connection;
function handleDisconnect() {
connection = mysql.createConnection(db_config); // Recreate the connection, since
// the old one cannot be reused.
connection.connect(function(err) { // The server is either down
if(err) { // or restarting (takes a while sometimes).
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
} // to avoid a hot loop, and to allow our node script to
}); // process asynchronous requests in the meantime.
// If you're also serving http, display a 503 error.
connection.on('error', function(err) {
console.log('db error', err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
handleDisconnect(); // lost due to either server restart, or a
} else { // connnection idle timeout (the wait_timeout
throw err; // server variable configures this)
}
});
}
handleDisconnect();
In your code i am missing the parts after connection = mysql.createConnection(db_config);
can you check this

Unable to connect to mysql database in nodejs application in gcp

I am unable to connect to my database hosted on cPanel from my Nodejs application in Google Cloud Platform.
I used Google Cloud Platform Cloud Shell, First I clone the application, second I run the command npm install and then npm start.
Application was unable to start when I run npm start.
Here's the error I am getting in Google Cloud Platform :-
/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Parser.js:437
throw err; // Rethrow non-MySQL errors
^
Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'ejekanshjain'#'35.185.177.100' (using password: YES)
at Handshake.Sequence._packetToError (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/sequences/Sequence.js:47:14)
at Handshake.ErrorPacket (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/sequences/Handshake.js:123:18)
at Protocol._parsePacket (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Protocol.js:291:23)
at Parser._parsePacket (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Parser.js:433:10)
at Parser.write (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Parser.js:43:10)
at Protocol.write (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Protocol.js:38:16)
at Socket.<anonymous> (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/Connection.js:91:28)
at Socket.<anonymous> (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/Connection.js:525:10)
at Socket.emit (events.js:182:13)
at addChunk (_stream_readable.js:283:12)
--------------------
at Protocol._enqueue (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Protocol.js:144:48)
at Protocol.handshake (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/protocol/Protocol.js:51:23)
at Connection.connect (/home/ejekanshjain/pams-rest-api/node_modules/mysql/lib/Connection.js:119:18)
at Object.<anonymous> (/home/ejekanshjain/pams-rest-api/db/db.js:14:16)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! pams-rest-api#1.0.0 start: `node server.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the pams-rest-api#1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ejekanshjain/.npm/_logs/2020-01-06T05_34_54_117Z-debug.log
Here's is my db file in nodejs :-
const mysql = require('mysql')
const dotenv = require('dotenv').config()
// Create connection to mysql database
const connection = mysql.createConnection({
host: 111.118.214.167,
user: ekanshjain,
password: password,
database: ekansh_db
})
// Open the MySQL connection
try {
connection.connect((err) => {
if (err) throw err
})
} catch (err) {
console.log("Error connecting to DB", err)
}
module.exports = connection
Can anyone suggest me why I am getting this and how could I solve this?

why does my node app works for a few moments on and crashes( heroku)?

i have deployed a nodejs app on heroku with ClearDb mysql, the app works for a few moments then crashes. i checked logs and got this errors
2019-09-20T19:03:41.536452+00:00 app[web.1]: events.js:174
2019-09-20T19:03:41.536474+00:00 app[web.1]: throw er; // Unhandled 'error' event
2019-09-20T19:03:41.536476+00:00 app[web.1]: ^
2019-09-20T19:03:41.536478+00:00 app[web.1]:
2019-09-20T19:03:41.536481+00:00 app[web.1]: Error: Connection lost: The server closed the connection.
2019-09-20T19:03:41.536483+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:112:13)
2019-09-20T19:03:41.536485+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2019-09-20T19:03:41.536488+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:525:10)
2019-09-20T19:03:41.53649+00:00 app[web.1]: at Socket.emit (events.js:203:15)
2019-09-20T19:03:41.536492+00:00 app[web.1]: at endReadableNT (_stream_readable.js:1145:12)
2019-09-20T19:03:41.536495+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-09-20T19:03:41.536497+00:00 app[web.1]: Emitted 'error' event at:
2019-09-20T19:03:41.536503+00:00 app[web.1]: at Connection._handleProtocolError (/app/node_modules/mysql/lib/Connection.js:426:8)
2019-09-20T19:03:41.536506+00:00 app[web.1]: at Protocol.emit (events.js:198:13)
2019-09-20T19:03:41.536509+00:00 app[web.1]: at Protocol._delegateError (/app/node_modules/mysql/lib/protocol/Protocol.js:398:10)
2019-09-20T19:03:41.536511+00:00 app[web.1]: at Protocol.end (/app/node_modules/mysql/lib/protocol/Protocol.js:116:8)
2019-09-20T19:03:41.536513+00:00 app[web.1]: at Socket.<anonymous> (/app/node_modules/mysql/lib/Connection.js:97:28)
2019-09-20T19:03:41.536515+00:00 app[web.1]: [... lines matching original stack trace ...]
2019-09-20T19:03:41.536517+00:00 app[web.1]: at process._tickCallback (internal/process/next_tick.js:63:19)
2019-09-20T19:03:41.599727+00:00 heroku[web.1]: Process exited with status 1
2019-09-20T19:03:41.653368+00:00 heroku[web.1]: State changed from up to crashed
This could be the problem
You can use the following code to handle the server disconnect
var db_config = {
host: 'localhost',
user: 'root',
password: '',
database: 'example'
};
var connection;
function handleDisconnect() {
connection = mysql.createConnection(db_config); // Recreate the connection, since
// the old one cannot be reused.
connection.connect(function(err) { // The server is either down
if(err) { // or restarting (takes a while sometimes).
console.log('error when connecting to db:', err);
setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
} // to avoid a hot loop, and to allow our node script to
}); // process asynchronous requests in the meantime.
// If you're also serving http, display a 503 error.
connection.on('error', function(err) {
console.log('db error', err);
if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
handleDisconnect(); // lost due to either server restart, or a
} else { // connnection idle timeout (the wait_timeout
throw err; // server variable configures this)
}
});
}
handleDisconnect();

Gulp Build command is failing with error " EISDIR: Illegal operation on directory"

I am trying to run the gulp build task for the dev environment on the server but its failing. However, The same gulp build is working on my local machine. The function and error are given below.
Function:
// S3 Upload for dev
gulp.task('s3sync:dev', function () {
var config = {
accessKeyId: "-Key-",
secretAccessKey: "-Key-"
};
var s3 = require('gulp-s3-upload')(config);
return gulp.src("./dist/**")
.pipe(s3({
Bucket: 'example',
ACL: 'public-read'
}, {
maxRetries: 5
}))
});
Command:
Gulp build:development
Error:
[09:01:04] Starting 's3sync:dev'...
events.js:160
throw er; // Unhandled 'error' event
^
Error: EISDIR: illegal operation on a directory, read
at Error (native)
Any idea?
Finally, This problem has been solved by removing a system symlink which was created after the deployment from the capistrano which is also running below npm commands.
npm run clean && npm run build
After removing the system file. I have run the below command and it works fine.
gulp build:development

Cannot connect to live database in Nodejs Openshift Application

I have no trouble connecting to the live database locally using port forwarding, but when we go to connect from the openshift gear, we get errors. Let me begin with the code:
Here is the connection variable
var connectionpool = mysql.createPool({
host : process.env.OPENSHIFT_MYSQL_DB_HOST,
port : process.env.OPENSHIFT_MYSQL_DB_PORT,
user : process.env.OPENSHIFT_MYSQL_DB_USERNAME,
password : process.env.OPENSHIFT_MYSQL_DB_PASSWORD,
database : 'stembuds',
socket : process.env.OPENSHIFT_MYSQL_DB_SOCKET
});
Here is an example of a query:
app.get('/answerDB/:course?/:answerID?', function(req, res){
var course = req.param('course');
var answerID = req.param('answerID');
connectionpool.getConnection(function(err, connection){
if(err){
console.error('CONNECTION error: ',err);
res.statusCode = 503;
res.send({
result: 'error',
err: err.code
});
}
if (course === undefined && answerID === undefined) {
connection.query('SELECT * FROM questions WHERE counter = 0', function(err, rows, fields){
if (err) {
console.error(err);
res.statusCode = 500;
res.send({
result: 'error',
err: err.code
});
}
for(var i in rows){
var newCourse = rows[i].course;
newCourse = courses[newCourse];
rows[i].course = newCourse;
}
res.send(rows);
connection.release();
});
}
Here are some errors we receive.
First is an error in the console of Chrome:
GET http://**.rhcloud.com/answerDB 503 (Service Temporarily Unavailable)
But sometimes we get a proxy error:
GET http://**.rhcloud.com/exploreDB 502 (Proxy Error)
Additionally, I have been running the command rhc tail -a nodejs and here is the error I am receiving
CONNECTION error: { [Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'adminMYXaSuf'#'127.11.28.130' (using password: YES)]
code: 'ER_ACCESS_DENIED_ERROR',
errno: 1045,
sqlState: '28000',
fatal: true }
TypeError: Cannot call method 'query' of undefined
at /var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/routes/site.js:172:15
at Pool.<anonymous> (/var/lib/openshift/5303aee55973ca4092000084/app- root/runtime/repo/node_modules/mysql/lib/Pool.js:49:16)
at Handshake.Sequence.end (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/sequences/Sequence.js:78:24)
at Handshake.ErrorPacket (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/sequences/Handshake.js:93:8)
at Protocol._parsePacket (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:202:24)
at Parser.write (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Parser.js:62:12)
at Protocol.write (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:37:16)
at Socket.<anonymous> (/var/lib/openshift/5303aee55973ca4092000084/app-root/runtime/repo/node_modules/mysql/lib/Connection.js:72:28)
at Socket.EventEmitter.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:720:14)
Now it says cannot call method query of undefined. We thought that was strange, so we changed 'connection.query' to 'connectionpool.query' and it then told us that it cannot call method release of undefined. So we changed 'connection.release()' to 'connectionpool.release()' and it told us that the object # has no method release. So I am taking that part of the error with a grain of salt.
We have no idea why it wont connect. Any information would be greatly appreciated - Thanks.
If your application code works locally while connecting to your remote OpenShift-hosted DB (using rhc port-forward), then I would suspect that your app may have some undocumented dependencies.
It could be that you've installed something locally (or globally) in your dev environment, without including that dep in your app's package.json file.
Make sure that everything your app needs in order to run in a fresh environment is included in your app's package.json file before pushing it to OpenShift.
npm install my_dependency --save
I've written up some additional notes that might be useful for testing locally with a port-forwarded connection to an OpenShift-hosted DB: https://www.openshift.com/blogs/set-up-local-access-to-openshift-hosted-services-with-port-forwarding
Did you create that database name? It should be the name of your application. You can use the OPENSHIFT_APP_NAME environment variable for your database name. Can you ssh into your gear and connect to mysql without any issues? Also, are you trying to connect to the database on your openshift gear from your local machine or from your openshift gear?