-
-
Notifications
You must be signed in to change notification settings - Fork 512
Error: This socket has been ended by the other party #67
Comments
A little progress. In mosca/node_modules/mqtt/lib/connection.js, line 49: var fun = "" +
" var p = this.generate." + v +"(opts); " +
" if (p instanceof Error) { " +
" this.emit('error', p) " +
" } else { " +
" this.stream.write(p) " +
" } "
" } "; stream.write is throwing an 'EPIPE' error. Try catch stops Mosca from falling over: " } else { " +
" try{this.stream.write(p);}catch(e){console.log('ERROR', e)} " +
" } " Appears to be specifically caused by the previous client connection being closed:
|
What version of node are you in? On node v0.10.21 I was not able to reproduce it using your script. |
My bad, I modified the client-test.js and didn't update the issue. Updated client.js: var mqtt = require('mqtt');
var c = 0;
var handleInterval = function()
{
var topic = '/ping/' + c;
c++;
client.publish(topic, '');
console.log('Published', topic);
}
var handleConnect = function()
{
console.log('Connected to mqtt broker with ClientId:', client.options.clientId);
client.subscribe('/ping/*');
}
var handleMessage = function(topic, message, packet)
{
console.log('Received Message, topic:', topic, 'message length:', message.length ,'message:', message);
}
console.log('Connecting to broker...');
var client = mqtt.createClient(1883, 'localhost');
client.on('connect' , handleConnect);
client.on('message' , handleMessage);
var timer = setInterval(handleInterval, 3000); Here are associated outputs from both Client test script and Mosca. User interaction involves starting and stopping Mosca via command. Environment is Win8 x64, Node v0.10.21. Also tested running Mosca under Ubuntu 13.04, Node v0.10.21 with similar results. Client Test:
Mosca:
|
Same test with Ubuntu. Here you can see the error is not always thrown on stop/restart of Mosca: Client.js console output:
Mosca Bunyan output:
|
Are you using the latest version of Mosca? Could you provide a test that exhibit this reliably? Otherwise it's very hard to debug and fix. Looking at node source shows that it's not throwing, but rather it's emitting an error: From the log it seems the connection has a problem and it is closed down, then Mosca try writing something more there. I think I got the problem, after this line https://github.com/mcollina/mosca/blob/master/lib/client.js#L495, try adding: // ignore all errors after we close
this.connection.on('error', function() {}); |
Cool, that appears to solve the issue: // ignore all errors after we close
that.connection.on('error', function() {}); |
Released as 0.13.3. |
I'm evaluating a scenario where Mosca needs to be restarted, thereby causing a temporary connection failure between the broker and the client.
I'm simulating this by starting the Broker from the command line:
then killing the process (CTRL-C) and restarting it.
Meanwhile, I have a simple NodeJS client which publishes every few seconds:
On restarting Mosca, it will regularly fail and throw the following error:
The problem appears to stem from MQTT lib during a connack event, though I'm not yet familiar enough with the relationship between the two libs to provide a solution.
The text was updated successfully, but these errors were encountered: