Sha256: d4316eb8b03f2680331bc113cbeb0045e2f4c821e9587e728bd7b05a6f00bc1c

Contents?: true

Size: 1.01 KB

Versions: 25

Compression:

Stored size: 1.01 KB

Contents

# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

# ensure that we're being loaded with an agent
# NOTE: THIS CLASS WILL NOT BE RELOADED B/C WE CANNOT RELOAD THE STANDARD
# thread file

# Request context is still tracked per-thread.  There isn't anything
# particularly order-dependent or stateful about request contexts.  It
# exists mostly for reference.
#
# Scope HAS to exist per-fiber.

# Monkey-patching Thread#initialize.
class Thread
  alias_method :cs__initialize, :initialize

  def initialize *args, &block
    # Thread.current still references the original(callee) thread that is
    # instantiating this new fiber during initialization
    Contrast::Components::Scope::MONITOR.synchronize do
      if (current_context = Thread.current[:current_context])
        self[:current_context] = current_context.dup
      end

      Contrast::Components::Scope.sweep_dead_ecs
    end

    cs__initialize(*args, &block)
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
contrast-agent-3.10.0 lib/contrast/extensions/ruby_core/thread.rb
contrast-agent-3.9.1 lib/contrast/extensions/ruby_core/thread.rb
contrast-agent-3.9.0 lib/contrast/extensions/ruby_core/thread.rb
contrast-agent-3.8.5 lib/contrast/core_extensions/thread.rb
contrast-agent-3.8.4 lib/contrast/core_extensions/thread.rb