Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure instrumentation durations are unique during threaded executions #658

Merged
merged 2 commits into from
Jan 10, 2025

Conversation

rabidpraxis
Copy link
Contributor

@rabidpraxis rabidpraxis commented Jan 10, 2025

We noticed some inconsistencies in the timing of some of our Insights events, so I ran some tests and was able to hackily replicate with multiple concurrent requests.

What I believe is happening is the Honeybadger::NotificationSubscriber is shared between all threads of the web server, and since we were using an instance variable to set the start time, if start is called multiple times without a called finish, we override the time.

This was a bear to test without getting really nasty. I opted to get sorta nasty and stub Process.clock_gettime to return an incrementing number only when called during the start method. This test is very brittle since it relies on caller stack. For concurrent executions, this would be overridden and the final durations would have duplicates. Please let me know if you have a better way to test this.

For the fix, I stored the start time in the payload, as that should be unique to each instrumentation dispatch.

@rabidpraxis rabidpraxis changed the title fix: Ensure instrumentation durations are unique during threaded executions fix: ensure instrumentation durations are unique during threaded executions Jan 10, 2025
Copy link
Member

@roelbondoc roelbondoc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome find. I think the test looks good too.

@rabidpraxis rabidpraxis merged commit 4c3f0a6 into master Jan 10, 2025
75 of 76 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants