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

Implement a thread-safe Airbrake::Context #659

Merged
merged 1 commit into from
Jun 17, 2021
Merged

Conversation

kyrylo
Copy link
Contributor

@kyrylo kyrylo commented Jun 17, 2021

Fixes #658 (Is Airbrake.merge_context thread safe?)

This makes sure any operations on the context hash are thread-safe. We do
synchronize calls around the code that attaches the context object to the error
report but the context object is not thread-safe itself.

@kyrylo kyrylo force-pushed the 658-thread-safe-context branch from f780472 to 8e9ae4a Compare June 17, 2021 11:37
Fixes #658 (Is Airbrake.merge_context thread safe?)

This makes sure any operations on the context hash are thread-safe. We do
synchronize calls around the code that attaches the context object to the error
report but the context object is not thread-safe itself.
@kyrylo kyrylo force-pushed the 658-thread-safe-context branch from 8e9ae4a to 84c2ec6 Compare June 17, 2021 11:45
@kyrylo kyrylo merged commit 36aa251 into master Jun 17, 2021
@kyrylo kyrylo deleted the 658-thread-safe-context branch June 17, 2021 14:24
Comment on lines +44 to +53
context "when another thread is spawned" do
it "doesn't clash with other threads' contexts" do
described_class.current.merge!(apples: 'oranges')
th = Thread.new do
described_class.current.merge!(foos: 'bars')
end
th.join
expect(described_class.current.to_h).to match(apples: 'oranges')
end
end
Copy link

Choose a reason for hiding this comment

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

👍

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.

Is Airbrake.merge_context thread safe?
2 participants