Hello,
I’m having trouble connecting my localghost docker (:latest) with an Azure managed Mysql database.
With the testing I’ve made, it seems the connection reset for no particular reason (timeout on the mysql is way above the treshold I encounter).
Running the docker as :
docker run -e database__client=mysql -e database__connection__port=3306 -e database__connection__host="mydatabase.mysql.database.azure.com" -e database__connection__user="myuser@mydatabase.mysql.database.azure.com" -e database__connection__password="mypassword" -e database__connection__database="mydb" -e url=http://localhost:3001 -p 3001:2368 ghost
Stacktrace :
[2022-06-29 13:44:26] INFO Ghost is running in production...
[2022-06-29 13:44:26] INFO Your site is now available on http://localhost:3001/
[2022-06-29 13:44:26] INFO Ctrl+C to shut down
[2022-06-29 13:44:26] INFO Ghost server started in 5.134s
[2022-06-29 13:44:28] WARN Database state requires migration.
node:events:505
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Connection instance at:
at Connection._notifyError (/var/lib/ghost/versions/5.2.3/node_modules/mysql2/lib/connection.js:236:12)
at Connection._handleFatalError (/var/lib/ghost/versions/5.2.3/node_modules/mysql2/lib/connection.js:167:10)
at Connection._handleNetworkError (/var/lib/ghost/versions/5.2.3/node_modules/mysql2/lib/connection.js:180:10)
at Socket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
the line “WARN Database state requires migration.” indicate that the connection went through, but why am I being disconnected ?
I have the same behavior using mysql2, both through ghost and simply using the ghost container with a vanilla nodejs connexion :
// index.js
const mysql = require("mysql2");
const fs = require("fs");
var conn = mysql.createConnection({
host: "mydatabase.mysql.database.azure.com",
user: "myuser@mydatabase.mysql.database.azure.com",
password: "mypassword",
database: "mydb",
port: 3306,
ssl: {
rejectUnauthorized: true,
ca: fs.readFileSync("./cert.pem", { encoding: "utf8", flag: "r" }),
},
});
//console.log(fs.readFileSync("./cert.pem", { encoding: "utf8", flag: "r" }))
console.log("SELECT COUNT(*) from users");
conn.query("SELECT COUNT(*) from users", function (err, rows, fields) {
if (err) console.log(err);
console.log("The solution is: ", rows);
conn.end();
});
stacktrace :
root@1e658727dcee:/test_mysql# node index.js
SELECT COUNT(*) from users
The solution is: [ { 'COUNT(*)': 8 } ]
node:events:505
throw er; // Unhandled 'error' event
^
Error: read ECONNRESET
at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20)
Emitted 'error' event on Connection instance at:
at Connection._notifyError (/test_mysql/node_modules/mysql2/lib/connection.js:236:12)
at Connection._handleFatalError (/test_mysql/node_modules/mysql2/lib/connection.js:167:10)
at Connection._handleNetworkError (/test_mysql/node_modules/mysql2/lib/connection.js:180:10)
at TLSSocket.<anonymous> (/test_mysql/node_modules/mysql2/lib/connection.js:350:14)
at TLSSocket.emit (node:events:527:28)
at TLSSocket._tlsError (node:_tls_wrap:906:8)
at TLSSocket.emit (node:events:527:28)
at emitErrorNT (node:internal/streams/destroy:157:8)
at emitErrorCloseNT (node:internal/streams/destroy:122:3)
at processTicksAndRejections (node:internal/process/task_queues:83:21) {
errno: -104,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
Any ideas of why I keep getting disconnected ? Running the above code on the docker host machine works just fine.
Regards,