lib/statsd/instrument/udp_sink.rb in statsd-instrument-3.2.1 vs lib/statsd/instrument/udp_sink.rb in statsd-instrument-3.3.0

- old
+ new

@@ -24,26 +24,31 @@ end def <<(datagram) with_socket { |socket| socket.send(datagram, 0) } self - rescue ThreadError - # In cases where a TERM or KILL signal has been sent, and we send stats as - # part of a signal handler, locks cannot be acquired, so we do our best - # to try and send the datagram without a lock. - socket.send(datagram, 0) > 0 rescue SocketError, IOError, SystemCallError => error StatsD.logger.debug do "[StatsD::Instrument::UDPSink] Resetting connection because of #{error.class}: #{error.message}" end invalidate_socket + self end private + def synchronize(&block) + @mutex.synchronize(&block) + rescue ThreadError + # In cases where a TERM or KILL signal has been sent, and we send stats as + # part of a signal handler, locks cannot be acquired, so we do our best + # to try and send the datagram without a lock. + yield + end + def with_socket - @mutex.synchronize { yield(socket) } + synchronize { yield(socket) } end def socket @socket ||= begin socket = UDPSocket.new @@ -51,10 +56,10 @@ socket end end def invalidate_socket - @mutex.synchronize do + synchronize do @socket = nil end end end end