node-mbed-dtls-client
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -0,1 +1,5 @@ | ||
# 1.0.2 | ||
* Fix send callback handling to prevent deadlock | ||
# 1.0.1 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "node-mbed-dtls-client", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "DTLS client created by wrapping mbedtls", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,23 +70,23 @@ 'use strict'; | ||
_sendEncrypted(msg) { | ||
if (!this.dgramSocket || !this.dgramSocket._handle) { | ||
if (this._sendCallback) { | ||
this._sendCallback(new Error('no underlying socket')); | ||
this._sendCallback = null; | ||
// store the callback here because '_write' might be called | ||
// again before the underlying socket finishes sending | ||
const sendCb = this._sendCallback; | ||
this._sendCallback = null; | ||
const sendFinished = (err) => { | ||
if (sendCb) { | ||
sendCb(err); | ||
} | ||
if (this._sendNotify) { | ||
process.nextTick(() => { | ||
this._closeSocket(); | ||
}); | ||
this._closeSocket(); | ||
} | ||
}; | ||
if (!this.dgramSocket || !this.dgramSocket._handle) { | ||
process.nextTick(() => { | ||
sendFinished(new Error('no underlying socket')); | ||
}); | ||
return; | ||
} | ||
this.dgramSocket.send(msg, 0, msg.length, this.remotePort, this.remoteAddress, err => { | ||
if (this._sendCallback) { | ||
this._sendCallback(err); | ||
this._sendCallback = null; | ||
} | ||
if (this._sendNotify) { | ||
this._closeSocket(); | ||
} | ||
}); | ||
this.dgramSocket.send(msg, 0, msg.length, this.remotePort, this.remoteAddress, sendFinished); | ||
} | ||
@@ -106,3 +106,8 @@ | ||
this._hadError = true; | ||
this.emit('error', code, msg); | ||
if (this._sendCallback) { | ||
this._sendCallback(code); | ||
this._sendCallback = null; | ||
} else { | ||
this.emit('error', code, msg); | ||
} | ||
this._end(); | ||
@@ -109,0 +114,0 @@ } |
8821307
192