Browse Source

set client/server socket atomically

session-estimator
Mathias Buus 3 years ago
parent
commit
d4866c8880
  1. 6
      lib/io.js

6
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
}

Loading…
Cancel
Save