Shopify / statsd-instrument

A StatsD client for Ruby apps. Provides metaprogramming methods to inject StatsD instrumentation into your code.
http://shopify.github.io/statsd-instrument
MIT License
574 stars 97 forks source link

Refactor BatchedUDPSink so that it can properly be GCed #285

Closed casperisfine closed 3 years ago

casperisfine commented 3 years ago

By moving the thread and the socket in another object, the thread no longer keep a reference on the BatchedUDPSink, which means it can be GCed, and it turn it can signal the dispatcher object to shutdown.

wvanbergen commented 3 years ago

We should probably try this (and the other changes we merged) out in production before cutting a release.

casperisfine commented 3 years ago

We should probably try this (and the other changes we merged) out in production before cutting a release.

Yes.

casperisfine commented 3 years ago

Hum, I'm having trouble with the GC test on CI, but somehow it passes 100% of the time locally 🤔

casperisfine commented 3 years ago

I tested it manually, it works well, I think it's just that the object must end up on the stakc somehow. Ruby Gc is unfortunately not 100 reliable. So I removed the finalizer test as I'd rather not introduce a flaky test.