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

Open
opened 2020-07-03 06:10:05 +00:00 by df257 · 2 comments
df257 commented 2020-07-03 06:10:05 +00:00 (Migrated from github.com)

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

if not have listen 'error', when I colse page, server will down. ![image](https://user-images.githubusercontent.com/7835444/86437169-8413df80-bd36-11ea-8e19-06c51d487206.png) ![image](https://user-images.githubusercontent.com/7835444/86437182-8b3aed80-bd36-11ea-8abf-1dad65ba2826.png)
littleQing commented 2021-07-15 07:57:47 +00:00 (Migrated from github.com)

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

I also encountered the same problem. Have you solved it ?
mepiazza commented 2022-12-05 22:27:05 +00:00 (Migrated from github.com)

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".

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 in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: sitegui/nodejs-websocket#61
No description provided.