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

DEV: Allow Net::HTTP#request patch to be applied with module prepend or method aliasing #444

Merged
merged 2 commits into from
Jun 11, 2020
Merged

DEV: Allow Net::HTTP#request patch to be applied with module prepend or method aliasing #444

merged 2 commits into from
Jun 11, 2020

Conversation

OsamaSayegh
Copy link
Collaborator

@SamSaffron what do you think about this? This will allow people to choose how our Net::HTTP is applied like we allow our Rails patches to be optional. People who want our Net::HTTP patch to be applied using module prepend, they can do something like this in their Gemfile:

gem 'rack-mini-profiler', require: ['prepend_net_http_patch']

Right now people who have other gems with patches that conflict with our patch are forced to either pin their Mini Profiler version and avoid updates, or remove one of the conflicting gems. I think it's nice if we can do something simple to avoid picking sides.

@SamSaffron
Copy link
Member

yes, this seems completely reasonable, be sure you update the readme though

@OsamaSayegh OsamaSayegh merged commit d7e3017 into MiniProfiler:master Jun 11, 2020
@OsamaSayegh OsamaSayegh deleted the net-http-patch-conflict branch June 11, 2020 04:17
glaszig added a commit to glaszig/rack-mini-profiler that referenced this pull request Jun 17, 2020
don't use alias_method since peek-mysql2 uses prepend on rails >= 5
related to MiniProfiler#437 and MiniProfiler#444
glaszig added a commit to glaszig/rack-mini-profiler that referenced this pull request Jan 23, 2021
don't use alias_method since peek-mysql2 uses prepend on rails >= 5
related to MiniProfiler#437 and MiniProfiler#444
ivoanjo added a commit to DataDog/logging that referenced this pull request Jun 15, 2021
Directly modifying the `Thread` class leads to
`stack level too deep (SystemStackError)` if other gems have prepended
modules to `Thread`, see for instance:

* <rollbar/rollbar-gem#1018>
* <MiniProfiler/rack-mini-profiler#444>
* <https://github.com/DataDog/dd-trace-rb/blob/master/docs/GettingStarted.md#stack-level-too-deep>

This behavior can be triggered with the following example app
(NOTE: the issue is triggered only on Linux, as due to unrelated
reasons the ddtrace gem only adds the module to `Thread` on that OS):

```ruby
require 'bundler/inline'

gemfile do
  source 'http://rubygems.org'

  gem 'logging', '= 2.3.0', require: false
  gem 'ddtrace', '= 0.50.0', require: false
  gem 'google-protobuf'
end

require 'ddtrace'

Datadog.configure do |c|
  c.profiling.enabled = true
end

require 'logging'

Thread.new { }.join
```

By changing context inheritance to use a `prepend`, it becomes
compatible with all libraries that use this technique as well.
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