Comments (7)
Thanks for the info, I'll look into this.
from honeybadger-ruby.
I wonder if using the Mutex class would solve the problem? http://www.ruby-doc.org/core-2.0.0/Mutex.html
from honeybadger-ruby.
A mutex on reads and writes would fix the issue, but that'd effectively only allow one request at a time. It wouldn't be terribly efficient.
from honeybadger-ruby.
Well, if this issue is only occurring when we duplicate the hash, I think we could get away with it there because it only happens every 60 seconds (when we send the metric data to the server). The duplication should happen relatively quickly, and the Mutex would prevent the race condition. Does that sounds right, or am I missing something?
from honeybadger-ruby.
This gem is also interesting, and looks similar to hamster: https://github.com/headius/thread_safe
from honeybadger-ruby.
The problem is you're reading while still writing to the hash. Putting a mutex around the read would just prevent two threads from reading at the same time . . . other threads would still be able to write. So you'd need to have the mutex around both the reads and the writes or come up with a ThreadLocal solution. Alternatively, you could push the dup from the read case to the write case, but you'd end up duping on every request. And without a mutex there, you could lose entries..
from honeybadger-ruby.
Cool, thanks for the help on this.
For posterity, it seems that the hamster gem provides thread safe constructs by making them immutable, however in our case we would still need to synchronize access to the metrics instance variable on every write. The thread_safe gem I mentioned above takes the second approach of wrapping every operation on the object in a mutex (or equivalent -- in JRuby, it uses the jruby/synchronized library, which appears to have been added to JRuby specifically for the thread_safe gem.
Since we're currently writing to the metrics hash in a single place and reading from it in a single place, I'm going to keep it simple and just add a lock in those two methods (Monitor#add_metric
and Monitor#send_metrics
). I'll revisit the need for an extra dependency or different approach once we further build out the metrics feature.
from honeybadger-ruby.
Related Issues (20)
- Add support for Hanami HOT 1
- `Honeybadger.notify` requires `error_message` to be specified when using a Hash HOT 4
- Documentation and source mismatch with Rails.error.record HOT 1
- `Honeybadger::Config#respond_to?` Always Returns true
- Help suppressing a certain error HOT 4
- Honeybadger CLI errors when the deploy command is called with any option HOT 3
- Minitest: Test Backend Notices Not Added to `Honeybadger::Backend::Test` HOT 9
- Invalid class_name param in documentation HOT 1
- Use nested context from objects where available
- Sidekiq 7.1.5 and later changes number of arguments for error handlers
- Add check-in configuration sync HOT 2
- Automate releases with Github Actions
- Flaky test in JRuby test matrix entry
- Allow check-ins to be made by slug as well as id. HOT 8
- Avoid bundling unnecessary dependencies in published gem HOT 3
- Exceptions raised in jobs from Solid Queue are not automatically reported HOT 10
- Sanitizer#filter_key? returns a warning for Numeric hash keys HOT 5
- ActiveJob premature reporting HOT 2
- ActiveJob rescued exceptions should not be reported HOT 2
- Honeybadger.context returns Honeybadger::Agent when passing a block
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from honeybadger-ruby.