moscajs / mosca

MQTT broker as a module
mosca.io
3.2k stars 508 forks source link

{"name":"mosca","hostname":"dev0003","pid":14618,"client":"push/4409b077adf1f29","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at errnoException (net.js:904:11)\n at TCP.onread (net.js:558:19)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-03-12T03:15:26.368Z","v":0} #226

Closed hongtoushizi closed 9 years ago

hongtoushizi commented 9 years ago

{"name":"mosca","hostname":"dev0003","pid":14618,"client":"push/4409b077adf1f29","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at errnoException (net.js:904:11)\n at TCP.onread (net.js:558:19)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-03-12T03:15:26.368Z","v":0}

why this happen? thanks!

mcollina commented 9 years ago

That error means a connection was truncated, which can happen if you CTRL-C your client. I think it might be normal or not, depending on your application. So, I cannot help you without more details.

As a side note, you might want to improve the way you report issues. I think there are a lot of guides on how to do that, which mainly consist:

  1. describe from a high level what is causing the problem, an exception without a stack trace is definitely not enough.
  2. provide detailed instructions in how to reproduce your issue, using only the module in question.
crapthings commented 9 years ago

{"name":"mosca","hostname":"Zhangs-MacBook-Pro.local","pid":6720,"client":"18FE349FBD19","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n at errnoException (net.js:905:11)\n at TCP.onread (net.js:559:19)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-03-19T03:26:36.635Z","v":0}

same here

the client is a wifi chip esp8266 which use mqtt-client from tuanpmt(link below) that running by a nodemcu firmware, and all mqtt client functions are using on lua interpreter which is a c module.

nodemcu mqtt part based on tuanpmt mqtt client lib https://github.com/nodemcu/nodemcu-firmware

mqtt client https://github.com/tuanpmt/esp_mqtt

The client code that i'm running which is basic client connect to mosca broker then subscribe a topic and send & receive message between those two.

i've set 1sec to send a "hello world" from esp8266 client through uart port, the broker received message but the esp8266 crashes and reboot sometimes then it will produce below error randomly.

i think it might be caused by mqtt-client lib or nodemcu.

mcollina commented 9 years ago

That error happen because the device crashed, it is a perfectly legit error condition. You should debug your devices.

JokerQyou commented 9 years ago

Will the last will message be sent if this happened?

PritamUpadhyay commented 9 years ago

@JokerQyou : Yes. will messages are stored (on broker) at the time of client connecting to broker. so in case of any abnormally disconnect event, broker will send this will message on topic specified in will option.

JokerQyou commented 9 years ago

But no, the will message did not get delivered if this happened. I was using Paho MQTT client for python, and what my client do is just connect to the broker, set the last will, and subscribe a topic. While the client is doing its network loop, I hit Ctrl-C and quit the terminal, and Mosca did not send the last will. I saw no delivering last will message as I expected. (This message will show up every time I close a webpage on which a WebSockets client is running. All I got is as follows:

{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"msg":"client connected","time":"2015-07-02T06:41:46.402Z","v":0}
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"topic":"zopen-default-users.admin-64ce64658ffde2440f172dc3bd9ab293","qos":1,"msg":"subscribed to topic","time":"2015-07-02T06:41:46.419Z","v":0}

{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":40,"err":{"message":"read ECONNRESET","name":"Error","stack":"Error: read ECONNRESET\n    at exports._errnoException (util.js:746:11)\n    at TCP.onread (net.js:559:26)","code":"ECONNRESET"},"msg":"read ECONNRESET","time":"2015-07-02T06:42:03.020Z","v":0}
{"name":"mosca","hostname":"85c0f86860aa","pid":11,"client":"zopen-users.admin-bhjRx6pE80Dt-4928e4a60625da560e35f85ff90713ff","level":30,"msg":"closed","time":"2015-07-02T06:42:03.021Z","v":0}
JokerQyou commented 9 years ago

In addition, I think I can confirm that the last will has been set right after the connection was established. The code is as follows:

def on_connect(client, userdata, flags, return_code):
    # 订阅自己的 topic
    print 'connected: ', return_code, flags
    client.will_set(topic=str(userdata['ref'].sys_topic), 
                    payload=json.dumps(userdata['ref'].gen_connection_msg(userdata, False)), 
                    qos=MSG_QOS, retain=False)
    print 'last will set'
    for topic in userdata['topics'].values():
        print 'subscribing ', topic
        client.subscribe(str(topic), qos=MSG_QOS)
JokerQyou commented 9 years ago

@PritamUpadhyay I know how it's described in the spec, but I'm having problem with the will message. I've updated details.

JokerQyou commented 9 years ago

Alright, I misunderstood part of the documentation, as at the time of client connecting to broker, so you have to set the will before connecting to the broker, otherwise the will message is not set.

PritamUpadhyay commented 9 years ago

@JokerQyou : Exactly.

contact-circularblue commented 7 years ago

You can probably try adding client.loop() after every subscription in your client code. Worked for us. We are using pubsubclient for esp8366 (https://github.com/knolleary/pubsubclient). ISSUE: https://github.com/marvinroger/homie-esp8266/issues/11