question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ECONNRESET when closing SSL connection not being handled to NodeJS Error spec

See original GitHub issue

Hi there, I receive the following error when closing a SSL connection that bubbles up:

{
  errno: -4077,
  code: "ECONNRESET",
  syscall: "read",
  stack:
    "Error: read ECONNRESET\n    at TLSWrap.onStreamRead (node:internal/stream_base_commons:220:20)\n    at TLSWrap.callbackTrampoline (node:internal/async_hooks:130:17)",
  message: "read ECONNRESET",
}

I’ve narrowed it down to the following lines that are mishandling the exception thrown:

// Line 160 of mysql2/lib/connection.js
 _handleNetworkError(err) {
    if (this.connectTimeout) {
      Timers.clearTimeout(this.connectTimeout);
      this.connectTimeout = null;
    }
    // Do not throw an error when a connection ends with a RST,ACK packet
    if (err.errno === 'ECONNRESET' && this._closing) {
      return;
    }
    this._handleFatalError(err);
  }

Issue seems to be that it’s looking for err.errno as a string. However, errno has exclusively been a negative number since Node 13, with err.code being the string that would emit ECONNRESET.

I see that this has been fixed in master. Can this please be released to npm?

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kpervincommented, Apr 12, 2022

Just met this one myself. Thankfully the patch-package utility exists so I can fix it for my codebase and move on.

Here’s my patch: mysql2_2.3.3.patch

diff --git a/node_modules/mysql2/lib/connection.js b/node_modules/mysql2/lib/connection.js
index 47970e9..4704db5 100644
--- a/node_modules/mysql2/lib/connection.js
+++ b/node_modules/mysql2/lib/connection.js
@@ -174,7 +174,7 @@ class Connection extends EventEmitter {
       this.connectTimeout = null;
     }
     // Do not throw an error when a connection ends with a RST,ACK packet
-    if (err.errno === 'ECONNRESET' && this._closing) {
+    if (err.code === 'ECONNRESET' && this._closing) {
       return;
     }
     this._handleFatalError(err);

That looks useful. I’ll have to look into it further. Thanks for the heads up!

0reactions
kpervincommented, May 25, 2022

@sidorares Will this be pushed to NPM? At present I am having to patch the repo via yarn patch in the meantime.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I debug error ECONNRESET in Node.js?
"ECONNRESET" means the other side of the TCP conversation abruptly closed its end of the connection. This is most probably due to one...
Read more >
0.10.x https/ssl and ECONNRESET error (part 2) #5360 - GitHub
ECONNRESET means the other end unexpectedly closed the connection but that's the 'what', not the 'why'. Can you post a test case?
Read more >
Errors | Node.js v19.3.0 Documentation
Indicates that an attempt is being made to access a variable that is not defined. Such errors commonly indicate typos in code, or...
Read more >
Nodejs HTTPS ECONNRESET ~ Ozkary
The https library in Nodejs enables us to make https calls to APIs under SSL/TLS protocols (encrypted channels).
Read more >
openssl enable legacy provider | The search engine you control.
Due to changes on Node.js v17, --openssl-legacy-provider was added for handling key size on OpenSSL v3. You somehow have installed the latest version...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found