Skip to content
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

Error: read ECONNRESET at TCP.onStreamRead (internal/stream_base_commons.js:111:27) Emitted 'error' event at: at Socket #61

Open
df257 opened this issue Jul 3, 2020 · 2 comments

Comments

@df257
Copy link

df257 commented Jul 3, 2020

if not have listen 'error', when I colse page, server will down.
image
image

@littleQing
Copy link

I also encountered the same problem. Have you solved it ?

@mepiazza
Copy link

mepiazza commented Dec 5, 2022

I encountered the same error for the same reason:

Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
Emitted 'error' event on Connection instance at:
    at Socket.<anonymous> (C:\Users\Mike\WebstormProjects\masc_webserver\node_modules\nodejs-websocket\Connection.js:70:8)
    at Socket.emit (events.js:315:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read'
}

There are line number differences and a module name difference but that is probably due to the time difference between the previous comments and mine. Testing for this error I found that closing the browser window, in both Chrome and Edge, does trip my "close" event handler, however, it immediately generates the above error as well even though my code is within a try/catch block. Firefox didn't generate a "close" or react in any way so because of that I had disallow the use of Firefox for this specific application. (It's a closed environment we can limit what is available to be used) I traced through the stack and found the line in the events.js module as well as the line in this module Connection.js. I had expected to see a fairly straightforward error handler in events.js but, unfortunately, what I did find was overly cryptic and I didn't have the time to waste try to figure out what it was doing.

I dropped back to Connection.js and modified the following code:

From this:

	socket.on('error', function (err) {
		that.emit('error', err)
	})

To this:

	socket.on('error', function (err) {
		// Filter out webpage disconnect ECONNRESET 'error'
		// that crashes the application server process
		if (err.toString() != "Error: read ECONNRESET") {
			that.emit('error', err)
		}
	})

First of all, I don't understand why this ECONNRESET is NOT already being handled by now. They say the caller needs to handle with a try/catch code block, well my code already has that and it doesn't work. Closing the active web page by clicking on the "X" in the upper right hand corner of the window frame is a pretty standard User web interaction which should NOT be causing the nodejs web server apps to crash. This may not be the proper "fix" but in all our testing, prior to the change, there were no other issues with ECONNRESET so we made the decision to filter and ignore it in the localized app copy of Connection.js located in the app's node_modules directory and document the fix for a "next time".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants