<commit_before>module Celluloid
  # A proxy which sends synchronous calls to an actor
  class SyncProxy < AbstractProxy
    attr_reader :mailbox

    # Used for reflecting on proxy objects themselves
    def __class__; SyncProxy; end

    def initialize(mailbox, klass)
      @mailbox, @klass = mailbox, klass
    end

    def inspect
      "#<Celluloid::SyncProxy(#{@klass})>"
    end

    def respond_to?(meth, include_private = false)
      __class__.instance_methods.include?(meth) || method_missing(:respond_to?, meth, include_private)
    end

    def method_missing(meth, *args, &block)
      unless @mailbox.alive?
        raise DeadActorError, "attempted to call a dead actor"
      end

      if @mailbox == ::Thread.current[:celluloid_mailbox]
        args.unshift meth
        meth = :__send__
      end

      call = SyncCall.new(::Celluloid.mailbox, meth, args, block)
      @mailbox << call
      call.value
    end
  end
end
<commit_msg>Avoid deadlocks when chaining synchronous calls<commit_after>module Celluloid
  # A proxy which sends synchronous calls to an actor
  class SyncProxy < AbstractProxy
    attr_reader :mailbox

    # Used for reflecting on proxy objects themselves
    def __class__; SyncProxy; end

    def initialize(mailbox, klass)
      @mailbox, @klass = mailbox, klass
    end

    def inspect
      "#<Celluloid::SyncProxy(#{@klass})>"
    end

    def respond_to?(meth, include_private = false)
      __class__.instance_methods.include?(meth) || method_missing(:respond_to?, meth, include_private)
    end

    def method_missing(meth, *args, &block)
      unless @mailbox.alive?
        raise DeadActorError, "attempted to call a dead actor"
      end

      if @mailbox == ::Thread.current[:celluloid_mailbox]
        args.unshift meth
        # meth = :__send__

        actor = Thread.current[:celluloid_actor]
        actor = actor.behavior.subject.bare_object
        return actor.__send__(*args)
      end

      call = SyncCall.new(::Celluloid.mailbox, meth, args, block)
      @mailbox << call
      call.value
    end
  end
end

{'fraction_non_alphanumeric': 0.08942307692307692, 'fraction_numerical': 0.0, 'mean_word_length': 2.9487666034155597, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3611184', 'n_tokens_mistral': 646, 'n_tokens_neox': 628, 'n_words': 175}