diff --git a/lib/io.js b/lib/io.js index c16dd1e..c16653c 100644 --- a/lib/io.js +++ b/lib/io.js @@ -133,16 +133,16 @@ module.exports = class IO { } async _bindSockets () { - this.serverSocket = typeof this._bind === 'function' ? await this._bind() : await bind.udp(this._bind) + const serverSocket = typeof this._bind === 'function' ? await this._bind() : await bind.udp(this._bind) try { // TODO: we should reroll the socket is it's close to our preferred range of ports // to avoid it being accidentally opened // We'll prop need additional APIs for that this.clientSocket = await bind.udp() + this.serverSocket = serverSocket } catch (err) { - await new Promise((resolve) => this.serverSocket.close(resolve)) - this.serverSocket = null + await new Promise((resolve) => serverSocket.close(resolve)) throw err }