node-mbed-dtls
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -0,1 +1,5 @@ | ||
# 1.3.3 | ||
* Fix send callback handling to prevent deadlock | ||
# 1.3.2 | ||
@@ -2,0 +6,0 @@ |
{ | ||
"name": "node-mbed-dtls", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Node mbed DTLS", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -49,24 +49,24 @@ 'use strict'; | ||
_sendEncrypted(msg) { | ||
// make absolutely sure the socket will let us send | ||
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._clientEnd) { | ||
process.nextTick(() => { | ||
this._finishEnd(); | ||
}); | ||
this._finishEnd(); | ||
} | ||
}; | ||
// make absolutely sure the socket will let us send | ||
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._clientEnd) { | ||
this._finishEnd(); | ||
} | ||
}); | ||
this.dgramSocket.send(msg, 0, msg.length, this.remotePort, this.remoteAddress, sendFinished); | ||
} | ||
@@ -86,3 +86,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(); | ||
@@ -89,0 +94,0 @@ } |
8839718
385