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 () { 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 { try {
// TODO: we should reroll the socket is it's close to our preferred range of ports // TODO: we should reroll the socket is it's close to our preferred range of ports
// to avoid it being accidentally opened // to avoid it being accidentally opened
// We'll prop need additional APIs for that // We'll prop need additional APIs for that
this.clientSocket = await bind.udp() this.clientSocket = await bind.udp()
this.serverSocket = serverSocket
} catch (err) { } catch (err) {
await new Promise((resolve) => this.serverSocket.close(resolve)) await new Promise((resolve) => serverSocket.close(resolve))
this.serverSocket = null
throw err throw err
} }

Loading…
Cancel
Save