mikronode-ng icon indicating copy to clipboard operation
mikronode-ng copied to clipboard

Crash in connection.js channels management

Open germon opened this issue 8 years ago • 17 comments

Hello,

I'm running into a crash that seems to be caused by a channel being closed prematurely. It's hard to pinpoint exactly what causes it but the more activity there is the more frequent it becomes.

The crash happens in connection.js, line 367: (this).channels[(this).currentChannelId] is undefined.

The app opens a connection to the router and a new channel for every command: channel = self.connection.openChannel(self.next_channel_id); channel.closeOnDone = true;

I use a simple counter as channel ID (1, 2, 3, 4, …) When the crash happens, _(this).currentChannelId is 1 less than the channel ID available in _(this).channels So it seems like there is a left-over result from the previous command but the channel is already closed.

I made a change to avoid the crash but that means the data currently in the buffer is simply ignored. So far I did not see any side effect but this is just a patch.

I hope this makes sense, let me know if you need further info.

Thanks for taking a look at this. Gerald.

germon avatar Oct 30 '16 02:10 germon

Here is the stack at time of crash: /home/gerald/server-demo/node_modules/mikronode-ng/lib/connection.js:367 (this).channels[(this).currentChannelId].data((this).packet);

TypeError: Cannot read property '_data' of undefined at Connection.sentence (/home/gerald/server-demo/node_modules/mikronode-ng/lib/connection.js:367:47) at Connection._read (/home/gerald/server-demo/node_modules/mikronode-ng/lib/connection.js:413:11) at Socket. (/home/gerald/server-demo/node_modules/mikronode-ng/lib/connection.js:495:10) 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)

germon avatar Oct 31 '16 02:10 germon

I should be able to take a look at this tonight.

gtjoseph avatar Oct 31 '16 14:10 gtjoseph

Hello, Do you have a new ETA ? Here it seems to happen more frequently when I ask the router to do some torching (/tools/torch). I also got some crashes after a connection to a router was fully closed and it could be caused by something similar, a packet arriving on a connection that is no longer watched. events.js:160 throw er; // Unhandled 'error' event Error: read ECONNRESET at exports._errnoException (util.js:1012:11) at TCP.onread (net.js:563:26)

I hope that helps. Thx!

germon avatar Nov 08 '16 03:11 germon

I apologize for the delay. For my day job I'm scrum-master for this sprint so I've been overly busy. I'm hoping for some time this weekend since the sprint ends Friday.

gtjoseph avatar Nov 09 '16 19:11 gtjoseph

While I was trying to find a solution for the other issue I have open, I think I might've run into this problem where the channel closes prematurely and it seems that it's being closed before it should here.

In my personal project I tested removing this line and adding the "closeChannel" from the Connection class inside the Channel class in the close function, after it was supposed to be closed. I don't know if that will solve the issue but it might be that the event 'close' is running before it should because of this.

aluisiora avatar Nov 11 '16 19:11 aluisiora

So it's been a while and I still live with the patch and regularly see it avoid a crash. One think I can add is that it seems to happen only with torch results (at least for me). I hope this catches you in a better time to take a look at this. Thanks!

germon avatar Jan 30 '17 05:01 germon

I'm trying to get caught up. Sorry for the delays.

gtjoseph avatar Feb 01 '17 13:02 gtjoseph

Ok, I did a little rearranging. See if v1.0.10 helps.

gtjoseph avatar Feb 05 '17 16:02 gtjoseph

I'll do that this week and let you know. Thx.

On Sun, Feb 5, 2017 at 11:28 PM, George Joseph [email protected] wrote:

Ok, I did a little rearranging. See if v1.0.10 helps.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/f5eng/mikronode-ng/issues/11#issuecomment-277530604, or mute the thread https://github.com/notifications/unsubscribe-auth/AGv9mQlDPhphLrEu8a2g4yjXoqJVhFyiks5rZfi0gaJpZM4KkRp7 .

germon avatar Feb 06 '17 04:02 germon

Sorry for my delay and I'm afraid I don't have good news. It's still the same crash but in a new place: connection.js line 367.

A the time of the crash, both _(this).channels and _(this).currentChannelId] have valid values, although obviously out of sync as (this).channels[(this).currentChannelId] is undefined.

Based on the content of _(this).packet, I can also confirm that it seems to keep happening with torch results, maybe only with torch results.

And it happens after I receive the channel.on 'done' event.

germon avatar Mar 09 '17 07:03 germon

Experiencing the same error intermittently,

  • node v6.10.1
  • mikrnode-ng v1.0.11
  • routeros-tile v6.38.5
C:\Users\AMeusel\Dropbox\GitHub\liberty-tree\node_modules\mikronode-ng\lib\connection.js:368
                                _(this).channels[_(this).currentChannelId]._data(_(this).packet);
                                                                          ^
TypeError: Cannot read property '_data' of undefined
    at Connection.sentence (C:\Users\AMeusel\Dropbox\GitHub\liberty-tree\node_modules\mikronode-ng\lib\connection.js:368:47)
    at Connection._read (C:\Users\AMeusel\Dropbox\GitHub\liberty-tree\node_modules\mikronode-ng\lib\connection.js:414:11)
    at Socket.<anonymous> (C:\Users\AMeusel\Dropbox\GitHub\liberty-tree\node_modules\mikronode-ng\lib\connection.js:496:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at Socket.Readable.push (_stream_readable.js:134:10)
    at TCP.onread (net.js:551:20)
function downloadDHCPLeases (retries) {
	connection.getConnectPromise().then(function(conn) {
		conn.getCommandPromise('/ip/dhcp-server/lease/print').then(function resolved(data) {
			parseDHCPLeases(data);
		}, function rejected(error) {
			retries++;
			if (retries >= 4) {
				console.log(colors.format('└─',timeSinceStart()),colors.error('Failed to download DHCP leases from',connection.host,error));
				setTimeout(function() {
					process.exit(0);
				},1000);
			} else {
				setTimeout(function() {
					downloadDHCPLeases(retries);
				},100);
			}
		});
	}).catch(function (error) {
		retries++;
		if (retries >= 4) {
			console.log(colors.format('└─',timeSinceStart()),colors.error('Failed to download DHCP leases from',connection.host,error));
			setTimeout(function() {
				process.exit(0);
			},1000);
		} else {
			setTimeout(function() {
				downloadDHCPLeases(retries);
			},100);
		}
	});
}

AndyMeusel avatar Apr 20 '17 09:04 AndyMeusel

@aluisiora Many Many Many thanks to you sir. Saved my day.

netrevisanto avatar Jul 28 '17 18:07 netrevisanto

@germon do you have a branch with this fix or a gist somewhere we could use? Seeing this error intermittently as well.

Jalle19 avatar Dec 10 '17 10:12 Jalle19

+1 still seeing the every day

AndyMeusel avatar Dec 11 '17 08:12 AndyMeusel

Does anyone know if this issue also occurs with https://github.com/Trakkasure/mikronode ?

Jalle19 avatar Dec 11 '17 11:12 Jalle19

Still seeing this

\mikronode-ng\lib\connection.js:368
                                _(this).channels[_(this).currentChannelId]._data(_(this).packet);
                                                                          ^

TypeError: Cannot read property '_data' of undefined
    at Connection.sentence (C:\Users\AMeusel\Dropbox\GitHub\DNS-DHCP-Monitor\node_modules\mikronode-ng\lib\connection.js:368:47)
    at Connection._read (C:\Users\AMeusel\Dropbox\GitHub\DNS-DHCP-Monitor\node_modules\mikronode-ng\lib\connection.js:414:11)
    at Socket.<anonymous> (C:\Users\AMeusel\Dropbox\GitHub\DNS-DHCP-Monitor\node_modules\mikronode-ng\lib\connection.js:496:10)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at addChunk (_stream_readable.js:266:12)
    at readableAddChunk (_stream_readable.js:253:11)
    at Socket.Readable.push (_stream_readable.js:211:10)
    at TCP.onread (net.js:585:20)

AndyMeusel avatar May 22 '18 13:05 AndyMeusel

While I was trying to find a solution for the other issue I have open, I think I might've run into this problem where the channel closes prematurely and it seems that it's being closed before it should here.

In my personal project I tested removing this line and adding the "closeChannel" from the Connection class inside the Channel class in the close function, after it was supposed to be closed. I don't know if that will solve the issue but it might be that the event 'close' is running before it should because of this.

I love you =) lol

ismametal avatar Feb 07 '23 14:02 ismametal