"read ECONNRESET" error is being thrown when trying to insert large size files.
See original GitHub issueHi,
when I am trying to insert large size files I’m getting the ECONNRESET error.
I’ve created the db connection pool and getting the connection using the pool.getConnection()
method.
Below is my scenario.
- I am getting the zip file from the web request.
- Then reading the file data using
fs.readFile()
method and trying to insert the file stream data into a table’s column oflongblob
datatype. - I’ve seen no issue when the zip file is below 2 mb to 3 mb size.
- When it excceds the above size I’m getting this issue.
- I’ve gone through similar issues reported in github but couldn’t able to fix it.
Stack Trace:
Error: read ECONNRESET
at exports._errnoException (util.js:1012:11)
at TCP.onread (net.js:563:26)
--------------------
at Protocol._enqueue (app\node_modules\mysql\lib\protocol\Protocol.js:141:48)
at PoolConnection.query (app\node_modules\mysql\lib\Connection.js:214:25)
at Query._callback (app\services\basedao.js:85:32)
at Query.Sequence.end (app\node_modules\mysql\lib\protocol\sequences\Sequence.js:86:24)
atQuery._handleFinalResultPacket(app\node_modules\mysql\lib\protocol\sequences\Query.js:144:8)
at Query.EofPacket (\node_modules\mysql\lib\protocol\sequences\Query.js:128:8)
at Protocol._parsePacket (app\node_modules\mysql\lib\protocol\Protocol.js:280:23)
at Parser.write (app\node_modules\mysql\lib\protocol\Parser.js:74:12)
at Protocol.write (app\node_modules\mysql\lib\protocol\Protocol.js:39:16)
at Socket.<anonymous> (E:\app\node_modules\mysql\lib\Connection.js:109:28)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:177:18)
at Socket.Readable.push (_stream_readable.js:135:10)
at TCP.onread (net.js:542:20)
My code:
var pool = mysql.createPool({
connectionLimit: 10,
host: process.env.HOSTNAME,
port: process.env.PORT,
user: process.env.USERNAME,
password: process.env.PASSWORD,
database: process.env.NAME,
debug: false
});
function insertpackage() {
getdbconnection(function(err, connection){
if (err) {
console.log('Failed to get connection');
}
else {
var sqlQuery = 'INSERT INTO user_packages SET ?';
/* fileData is the stream that is read from my zip file */
var params = {
fileName: name,
content: fileData
};
connection.query(sqlquery, params, function (err, result) {
connection.release();
if (err) {
console.log( 'Error in executing Insert query :' + err.stack);
}
else {
console.log('Package uploaded successfully');
}
});
}
});
}
function getdbconnection(callback) {
pool.getConnection(function (err, dbconnection) {
if (err) {
console.log('Error in acquiring DB Connection :', err);
callback(null, null);
}
else {
console.log('Acquired Database Connection with Connection Id as :' + dbconnection.threadId);
callback(null, dbconnection);
}
});
}
Issue Analytics
- State:
- Created 6 years ago
- Comments:14 (2 by maintainers)
Top Results From Across the Web
Error: read ECONNRESET when inserting data into table
And the SQL request is: INSERT INTO schedules (trainNumber, stopName, baseArrivalTime, baseDepartureTime, beginDate, endDate, updatedOn) VALUES ...
Read more >Fixing an ECONNRESET error - Postman
The ECONRESET error means that the server unexpectedly closed the connection and the request to the server was not fulfilled. Connection-related ...
Read more >node-mssql | Microsoft SQL Server client for Node.js
const sql = require('mssql') async () => { try { // make sure that any items are correctly ... or a connection.on is...
Read more >Error: read ECONNRESET when connected to a mysql server ...
Coding example for the question Error: read ECONNRESET when connected to a mysql server with Node.js-node.js.
Read more >List of OS error codes | QuestDB: the database for time series
List of OS error codes that may be reported by QuestDB running on Linux and Windows.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am facing this same issue. When the file’s size is greater than 4 mb the ECONNRESET is thrown. I have succesfully inserted the same file straight to the database using MySQL without node, which led me to believe this is a node issue. My code looks like that:
And i get:
I’m building an API that track the database’s binlog files and when it reach 4mb “read ECONNRESET” error is thrown.
Any update on it?