PubNub Ruby SDK:Celluloid :: DeadActorError:试图调用一个死的actor:fetch_average

时间:2017-10-13 23:34:36

标签: ruby-on-rails ruby pubnub celluloid

我正在尝试使用PubNub Ruby SDK 4.0.25运行一个简单的Ruby代码,但是在运行ruby subscriber.rb时我收到的日志错误如下所示:

# Logfile created on 2017-10-14 01:09:02 +0200 by logger.rb/56815
D, [2017-10-14T01:09:02.580516 #1990] DEBUG -- Pubnub::Telementry: Initialized Telemetry
D, [2017-10-14T01:09:02.580628 #1990] DEBUG -- Pubnub::Client: Created new Pubnub::Client instance. Version: 4.0.25
D, [2017-10-14T01:09:02.581081 #1990] DEBUG -- Pubnub::Event: Initialized Pubnub::Subscribe
D, [2017-10-14T01:09:02.581125 #1990] DEBUG -- Pubnub::Client: Apply state
D, [2017-10-14T01:09:02.581443 #1990] DEBUG -- Pubnub::Subscriber: Adding subscription to Subscriber
D, [2017-10-14T01:09:02.582156 #1990] DEBUG -- Pubnub::Subscriber: Added subscription to Subscriber
D, [2017-10-14T01:09:02.582521 #1990] DEBUG -- Pubnub::Event: Initialized Pubnub::Subscribe
D, [2017-10-14T01:09:02.582557 #1990] DEBUG -- Pubnub::Client: Apply state
D, [2017-10-14T01:09:02.582862 #1990] DEBUG -- Pubnub::Subscriber: Starting subscription
D, [2017-10-14T01:09:02.583102 #1990] DEBUG -- Pubnub: Fired event Pubnub::Subscribe
D, [2017-10-14T01:09:02.583131 #1990] DEBUG -- Pubnub: #send_request start
D, [2017-10-14T01:09:02.583147 #1990] DEBUG -- Pubnub: #request_dispatcher
D, [2017-10-14T01:09:02.583176 #1990] DEBUG -- Pubnub::Client: Looking for requester for async subscribe_event
D, [2017-10-14T01:09:02.583670 #1990] DEBUG -- Pubnub::Event: Requested URI: http://ps.pndsn.com/v2/subscribe/sub-c-3b21e31a-a94f-11e7-80f2-f610152a0f4c/test_789/0?pnsdk=PubNub-Ruby%2F4.0.25&t=%7B%22r%22%3A0%2C%22t%22%3A0%7D&uuid=f568bd89-01c7-460f-a914-fe2d61116aca
D, [2017-10-14T01:09:03.060193 #1990] DEBUG -- Pubnub: Fire before fire_callback
E, [2017-10-14T01:09:03.060408 #1990] ERROR -- : Actor crashed!
Celluloid::DeadActorError: attempted to call a dead actor: fetch_average
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/proxy/sync.rb:9:in `method_missing'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/client.rb:310:in `telemetry_for'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/event.rb:76:in `uri'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/subscribe_event.rb:38:in `fire'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `public_send'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `dispatch'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/call/sync.rb:16:in `dispatch'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:50:in `block in dispatch'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:76:in `block in task'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/actor.rb:339:in `block in task'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/task.rb:44:in `block in initialize'
  /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/task/fibered.rb:14:in `block in create'

这就是subscriber.rb文件的样子:

require_relative 'client'

Client.new.pubnub.subscribe(
    channel: 'test_channel'
)

其中client.rb

require 'pubnub'

class Client
  attr_reader :pubnub

  def initialize
    @pubnub = Pubnub.new(
      publish_key: 'pub-c-some_proper_pub_key',
      subscribe_key: 'sub-c-some_proper_sub_key'
    )

    setup_listener
  end

  def setup_listener
    callback = Pubnub::SubscribeCallback.new(
      message:  ->(envelope) {
          puts "MESSAGE: #{envelope.result[:data]}"
      }
    )

    pubnub.add_listener(callback: callback)
  end
end

我在2.4.1版本中使用Ruby(我也尝试过2.3.3,2.4.0,2.4.2)这就是我Gemfile的样子(我尝试过pubnub gem)在4.0.23版本中):

source 'https://rubygems.org' do
  gem 'pubnub', '~> 4.0.25'
end

Gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    celluloid (0.17.3)
      celluloid-essentials
      celluloid-extras
      celluloid-fsm
      celluloid-pool
      celluloid-supervision
      timers (>= 4.1.1)
    celluloid-essentials (0.20.5)
      timers (>= 4.1.1)
    celluloid-extras (0.20.5)
      timers (>= 4.1.1)
    celluloid-fsm (0.20.5)
      timers (>= 4.1.1)
    celluloid-pool (0.20.5)
      timers (>= 4.1.1)
    celluloid-supervision (0.20.6)
      timers (>= 4.1.1)
    coderay (1.1.2)
    concurrent-ruby (1.0.5)
    dry-configurable (0.7.0)
      concurrent-ruby (~> 1.0)
    dry-container (0.6.0)
      concurrent-ruby (~> 1.0)
      dry-configurable (~> 0.1, >= 0.1.3)
    dry-core (0.3.4)
      concurrent-ruby (~> 1.0)
    dry-equalizer (0.2.0)
    dry-logic (0.4.2)
      dry-container (~> 0.2, >= 0.2.6)
      dry-core (~> 0.2)
      dry-equalizer (~> 0.2)
    dry-types (0.12.1)
      concurrent-ruby (~> 1.0)
      dry-configurable (~> 0.1)
      dry-container (~> 0.3)
      dry-core (~> 0.2, >= 0.2.1)
      dry-equalizer (~> 0.2)
      dry-logic (~> 0.4, >= 0.4.2)
      inflecto (~> 0.0.0, >= 0.0.2)
    dry-validation (0.11.1)
      concurrent-ruby (~> 1.0)
      dry-configurable (~> 0.1, >= 0.1.3)
      dry-core (~> 0.2, >= 0.2.1)
      dry-equalizer (~> 0.2)
      dry-logic (~> 0.4, >= 0.4.0)
      dry-types (~> 0.12.0)
    hitimes (1.2.6)
    httpclient (2.8.3)
    inflecto (0.0.2)
    json (2.1.0)
    method_source (0.9.0)
    pry (0.11.1)
      coderay (~> 1.1.0)
      method_source (~> 0.9.0)
    pubnub (4.0.25)
      celluloid (~> 0.17)
      dry-validation (~> 0.10)
      httpclient (~> 2.8, >= 2.8.3)
      json (>= 1.8, < 3)
    timers (4.1.2)
      hitimes

PLATFORMS
  ruby

DEPENDENCIES
  pry!
  pubnub (~> 4.0.25)!

BUNDLED WITH
   1.15.4

这是publisher.rb档案:

require_relative 'client'

Client.new.pubnub.publish(
    channel: 'test_channel',
    message: { text: "Hi! Message from PUBLISHER! #{Time.now}" }
) do |envelope|
    puts envelope.status
end

publisher.rb的输出提供了这样的日志跟踪:

    D, [2017-10-14T01:22:08.125841 #3009] DEBUG -- Pubnub::Telementry: Initialized Telemetry
    D, [2017-10-14T01:22:08.126657 #3009] DEBUG -- Pubnub::Client: Created new Pubnub::Client instance. Version: 4.0.25
    D, [2017-10-14T01:22:08.127096 #3009] DEBUG -- Pubnub::Event: Initialized Pubnub::Publish
    D, [2017-10-14T01:22:08.127401 #3009] DEBUG -- Pubnub::Publish: Fired event Pubnub::Publish
    D, [2017-10-14T01:22:08.127430 #3009] DEBUG -- Pubnub::Event: #send_request called
    D, [2017-10-14T01:22:08.127446 #3009] DEBUG -- Pubnub::SingleEvent: #request_dispatcher called
    D, [2017-10-14T01:22:08.127463 #3009] DEBUG -- Pubnub::Client: Looking for requester for async single_event
    D, [2017-10-14T01:22:08.127646 #3009] DEBUG -- Pubnub::Event: #send_request got sender
    D, [2017-10-14T01:22:08.128004 #3009] DEBUG -- Pubnub::Event: Requested URI: http://ps.pndsn.com/publish/pub-c-4f29acc4-caaf-4037-8bf5-5a93361121d8/sub-c-3b21e31a-a94f-11e7-80f2-f610152a0f4c/0/test_789/0/%7B%22text%22%3A%22Hi%21%20Message%20from%20PUBLISHER%21%20%28%E2%95%AD%E2%98%9E%E2%96%A0%E2%88%80%E2%96%A0%29%E2%95%AD%E2%98%9E%202017-10-14%2001%3A22%3A08%20%2B0200%22%7D?ortt=%7B%22t%22%3A15079369281271240%7D&pnsdk=PubNub-Ruby%2F4.0.25&seqn=1&uuid=5d73c0c5-5977-4d4c-8373-b6d8b8cee80a
    D, [2017-10-14T01:22:08.450584 #3009] DEBUG -- Pubnub::Event: Event#handle
    E, [2017-10-14T01:22:08.451594 #3009] ERROR -- : Actor crashed!
    NoMethodError: undefined method `body' for #<Celluloid::DeadActorError:0x007faf8e0c12b0>
        /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/event/formatter.rb:11:in `format_envelopes'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/event.rb:129:in `handle'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/pubnub-4.0.25/lib/pubnub/events/publish.rb:36:in `fire'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `public_send'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/calls.rb:28:in `dispatch'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/call/sync.rb:16:in `dispatch'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:50:in `block in dispatch'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/cell.rb:76:in `block in task'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/actor.rb:339:in `block in task'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/task.rb:44:in `block in initialize'
        /Users/user/.rvm/gems/ruby-2.4.1/gems/celluloid-0.17.3/lib/celluloid/task/fibered.rb:14:in `block in create'

我无法用Celluloid::DeadActorError解决这个问题,我希望有人能为我提供一些如何处理它的线索。有趣的是,当我在2个月前运行此代码时,它工作得很好。

1 个答案:

答案 0 :(得分:1)

我已经联系了PubNub支持,结果发现pubnub gem版本4.0.25中存在一个bug,它涉及一个新功能 - 遥测。目前降级到4.0.23解决了这个问题(使用Ruby 2.4.0)。