moscajs / mosca

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

TLS Handshake Failure #609

Closed hicaro closed 7 years ago

hicaro commented 7 years ago

After the TLS certificate used by the broker expired, mosca started to not treat the following error properly when a client attempts to connect:

{ "pid": 31532, "hostname": "...", "name": "mosca", "level": 40, "time": 1487192880702, "msg": "47310591870208:error:140940E5:SSL routines:SSL3_READ_BYTES:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1026:", "type": "Error", "stack": "Error: 47310591870208:error:140940E5:SSL routines:SSL3_READ_BYTES:ssl handshake failure:../deps/openssl/openssl/ssl/s3_pkt.c:1026:\n\n at Error (native)", "client": "40ad36e2", "v": 1 }

The broker does not crash, however it prints the message out at every new connection attempt. Ater renewing the certificate, it stopped.

mcollina commented 7 years ago

How should this error be handled?

hicaro commented 7 years ago

When it happens, instead of printing it out to the console, a .emit("error", ...) could be used.

Then, inside the user's code it could be caught and treated the way he/she prefers:

// fired when a message is received
server.on('error', function(error) {
    // do whatever with the it 
});

By the way, thank you so much for the library!

mcollina commented 7 years ago

would you mind sending a PR?

hicaro commented 7 years ago

Will do!

Thanks.