uber-archive / node-statsd-client

Node.js client for statsd
ISC License
28 stars 9 forks source link

_socket is undefined under some conditions in allocSocket which throws an error #29

Closed lxe closed 8 years ago

lxe commented 9 years ago
web_1    | /.../node_modules/uber-statsd-client/lib/EphemeralSocket.js:185
web_1    |         self._socket.on('error', function onDeadSocketError() {
web_1    |                     ^
web_1    | TypeError: Cannot read property 'on' of undefined
web_1    |     at Socket.onError (/.../node_modules/uber-statsd-client/lib/EphemeralSocket.js:185:21)
web_1    |     at Socket.g (events.js:199:16)
web_1    |     at Socket.emit (events.js:107:17)
web_1    |     at dgram.js:319:12
web_1    |     at GetAddrInfoReqWrap.asyncCallback [as callback] (dns.js:81:16)
web_1    |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:94:17)
web_1    | 31 Jul 21:05:33 - [nodemon] app crashed - waiting for file changes before starting...

This happens here: https://github.com/uber/node-statsd-client/blob/master/lib/EphemeralSocket.js#L185

Which is very strange... looks like the handler fires twice, dereferencing the _socket on the first invocation.

Investigating...

Raynos commented 9 years ago

Let's fix it by var udpSocket = self._socket to work around mutations