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

Prevent overpatching Rails #352

Merged
merged 2 commits into from
Feb 21, 2018
Merged

Prevent overpatching Rails #352

merged 2 commits into from
Feb 21, 2018

Conversation

delner
Copy link
Contributor

@delner delner commented Feb 20, 2018

In our current implementation, although there are guards around the Rails::Patcher module, there are no such guards around the constituent modules (e.g. in CoreExtensions) it uses to actually patch Rails code. It's possible to call these and overpatch Rails methods, causing infinite loops and other nasty behaviors. This has actually occurred when Railties reload, as they do in our test suite.

This pull request adds a helper function to Datadog::Patcher called do_once which is a really simple singleton-like function that prevents a function being called more than once. It's equivalent to the old return @patched if @patched; patcher.patch_code; @patched = true, just a little nicer looking and abstracts away the pattern.

I think this one could warrant some critical opinion, since the new function brings up questions about the direction of our patching API.

@delner delner added bug Involves a bug core Involves Datadog core libraries integrations Involves tracing integrations labels Feb 20, 2018
@delner delner added this to the 0.11.3 milestone Feb 20, 2018
@delner delner self-assigned this Feb 20, 2018
Copy link
Member

@p-lambert p-lambert left a comment

Choose a reason for hiding this comment

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

Nice!

end
end

def do_once(key = nil)
Copy link
Member

Choose a reason for hiding this comment

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

👍

@delner delner merged commit 9650a26 into master Feb 21, 2018
@delner delner mentioned this pull request Feb 21, 2018
@palazzem palazzem deleted the bugfix/rails_overpatching branch February 22, 2018 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Involves a bug core Involves Datadog core libraries integrations Involves tracing integrations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants