-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ConnectionError: Connection lost - write ECONNRESET when inserting long string #923
Comments
We run into a similar issue. when trying to insert a long string. After a bit of testing it turns out, that for us it is related to the used nodejs version in our case dockerized. |
Hi @ricklang, I was looking int this. Is "encrypt: true" a required setting on your side? If it is not, then set it to false or just do not set it in the option which using the default value -false can also resolve these issues. I was trying to figure out why this is happening, but I have not found a root cause for this. I checked the packets for both encrypt and non-encrypt connection, the packets are exactly the same, but for encrypting one, when the last packet with EOM is received, the connection lost error is received. I will give a bit more investigation, see if I can dig up anything. |
With
Error message is (no matter what the packet size is):
If remove encrypt setting, but leave the packet size at 4096, error message is:
But if increases packet size to 16384 with no encrypt set, everything works fine. By the way, I tested for node versions: 12.4.0, 12.6.0. Same results. |
Got node version: |
@wy193777 could you check if everything works without additional options and using node version at max 12.3.1 ? |
@susares node v12.3.1 works without packetSize option works for me. |
node version: v12.2.0 works without packetSize option |
This seems to be due to nodejs/node#27861. Somehow, SQLServer will end the connection if large TLS segments are written. I do have a fix and will open a PR shortly. 👍 For those who can't wait, here's the diff that will fix this: diff --git a/src/message-io.js b/src/message-io.js
index 90875f8..79f5da8 100644
--- a/src/message-io.js
+++ b/src/message-io.js
@@ -72,6 +72,8 @@ module.exports = class MessageIO extends EventEmitter {
encrypted: duplexpair.socket2
};
+ securePair.cleartext.setMaxSendFragment(this.outgoingMessageStream.packetSize);
+
// If an error happens in the TLS layer, there is nothing we can do about it.
// Forward the error to the socket so the connection gets properly cleaned up.
securePair.cleartext.on('error', (err) => { |
🎉 This issue has been resolved in version 6.2.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Facing this issue when performing bulk insert op. When I truncate the query its working fine. node: 16.8.0 |
For whoever is still struggling with any of the following issues encrypt: true,
packetSize: 16368 |
The issue still exists. Tried all the workarounds mentioned in the thread. Is there any other way to fix this issue. Seeing this issue on read operation. |
I am still facing this error, do we have any other fix or workaround. |
Hi @imtiyazthange, I assume you have already tried the fix and configuration settings mentioned in this thread. I am wondering, which version of tedious and node are you currently on? If possible, can you post your connection configuration here? In this way, we can try to reproduce the behavior with the same setup. Thanks! |
I am using node-mssql version (7.1.4) not tedious, but node-mssql reference tedious internally (version 4.0.0)
|
@imtiyazthange Can you try upgrading Tedious to a version that is at least 6.2.1? |
Requiring tedious 6.2.1 in my project rather than depending on mssql's minimum version fixed the issue for me. Even though I had updated mssql, the version of tedious was still an issue.
Thank you! |
Awesome! Glad it worked out. |
can you help me for this? i also get this fail. |
Hi @RSS1102, what Tedious version are you using? |
Hi, I'm encountering the same issue using |
Hi @deltarays, if you're still experiencing this problem, could you open a new issue? We can assist you from there. I couldn't reproduce this issue using either of the latest versions of Tedious or mssql on Node 12, 14, or 16. |
I will, thanks! Should I make the issue in tediousjs/tedious or in tediousjs/node-mssql? |
You can open it under tediousjs/tedious |
Okay, I was able to find a solution to the issue: |
i get the ConnectionError ConnectionError: Connection lost - read ECONNRESET with using the 1434 port , and the sql server browser is listening to the 1434 port too , is it the issue to make the connection error? |
Hi @kin-for-test , for this error, can you share with us your connation config set up as well as the error log. These information may help us understand the issue better. If is not too much trouble, you can also open up an new issue, so we can better track the conversions. |
HI @MichaelSun90 ,i using node-mssql to connect db , but it seem like the tedious error, i create a issues in node-mssql , link:tediousjs/node-mssql#1467 , thank ! |
Using typeorm I have set this config: pool: { It limits the number of connection to 1 rather than 10. |
Hey everyone, Software Versions: |
Try this one: |
@mattdeba thank you for your suggestion. But I fixed my issue by using a different SQL server. Initially I was using SQL server 2022 which was causing this error for some reason, but after shifting to Azure's SQL server my script worked completely fine. To anyone else who is getting this error, try a different SQL server (like Azure's SQL server or SQL server 2019). |
Adjusting the packageSize was the key for me. It seems Azure SQL DB requires a dedicated size definition for queries with a high number of chars |
I have a table on an Azure SQL Database.
I tried to insert very long string to the Signature column. If the packetSize is not set to 16384 or higher, I got the following exception:
Below is my simple test program. I use the latest tedious. Also the read operation seems to work fine for long string no matter what the packet size is. Any idea what I did wrong?
The text was updated successfully, but these errors were encountered: