Giter VIP home page Giter VIP logo

Comments (9)

palkan avatar palkan commented on June 18, 2024 4

Added information to the Troubleshooting guide: https://docs.anycable.io/#/troubleshooting?id=authentication-fails-with-undefined-method-39protocol39-for-nilnilclass

from anycable-rails.

subhashsaran avatar subhashsaran commented on June 18, 2024 2

Ahh, Figured it out. issue turned out to be because we are using lograge in production which override action cable connection handler. I think anycable override somehow leave websocket to nil.
https://github.com/roidrage/lograge/blob/master/lib/lograge/rails_ext/action_cable/connection/base.rb#L8

from anycable-rails.

leoc avatar leoc commented on June 18, 2024 1

Thank you for the work-around, @palkan!

I had to use super for closing connections, otherwise it complained about no block given for yield:

#  config/lograge_fix/lograge/rails_ext/action_cable/connection/base.rb 
module Lograge
  module ActionCable
    module ConnectionInstrumentation
      def handle_open
        ActiveSupport::Notifications.instrument("connect.action_cable", notification_payload("connect")) { super }
      end

      def handle_close
        ActiveSupport::Notifications.instrument("disconnect.action_cable", notification_payload("disconnect")) { super }
      end

      def notification_payload(method_name)
        {connection_class: self.class.name, action: method_name, data: request.params}
      end
    end
  end
end

ActionCable::Connection::Base.prepend(Lograge::ActionCable::ConnectionInstrumentation)

from anycable-rails.

ryansch avatar ryansch commented on June 18, 2024 1

@palkan I just hit this today and found your fixed version in roidrage/lograge#310. Thanks!!

from anycable-rails.

palkan avatar palkan commented on June 18, 2024

Yep, that’s a lograge issue: roidrage/lograge#257 (comment)

Will add it to Troubleshooting.

from anycable-rails.

brunoalano avatar brunoalano commented on June 18, 2024

Please, display a information about this on frontpage or some wiki.

from anycable-rails.

palkan avatar palkan commented on June 18, 2024

How are people solving this besides avoiding using lograge?

UPDATED on 2020-05-05

The best way is to fork lograge and fix the way they do the monkey-patching.
We can do this by making Ruby load proper patches instead of Lograge ones.

Here is how we can do that.

  1. Create a config/lograge_fix folder with the following structure:
config/
  lograge_fix/
    lograge/
      rails_ext/
        action_cable/
          channel/
            base.rb
          connection/
            base.rb

We want to have the exact structure as [Lograge has](https://github.com/roidrage/lograge/blob/1729eab7956bb95c5992e4adab251e4f93ff9280/lib/lograge.rb#L156.

The contents of the patches are the following:

#  config/lograge_fix/lograge/rails_ext/action_cable/channel/base.rb
module Lograge
  module ActionCable
    module ChannelInstrumentation
      def subscribe_to_channel
        ActiveSupport::Notifications.instrument("subscribe.action_cable", notification_payload("subscribe")) { super }
      end

      def unsubscribe_from_channel
        ActiveSupport::Notifications.instrument("unsubscribe.action_cable", notification_payload("unsubscribe")) { super }
      end

      private

      def notification_payload(method_name)
        {channel_class: self.class.name, action: method_name}
      end
    end
  end
end

ActionCable::Channel::Base.prepend(Lograge::ActionCable::ChannelInstrumentation)


#  config/lograge_fix/lograge/rails_ext/action_cable/connection/base.rb 
module Lograge
  module ActionCable
    module ConnectionInstrumentation
      def handle_open
        ActiveSupport::Notifications.instrument("connect.action_cable", notification_payload("connect")) { super }
      end

      def handle_close
        ActiveSupport::Notifications.instrument("disconnect.action_cable", notification_payload("disconnect")) { yield }
      end

      def notification_payload(method_name)
        {connection_class: self.class.name, action: method_name, data: request.params}
      end
    end
  end
end

ActionCable::Connection::Base.prepend(Lograge::ActionCable::ConnectionInstrumentation)
  1. Now we need to tell Ruby to load our patches instead of Lograge ones. For that, we should add our lograge_fix folder to the beginning of the $LOAD_PATH.

In your config/application.rb, right after require "boot" add the following line:

$LOAD_PATH.unshift(File.join(__dir__, "lograge_fix"))

That's it! Now Lograge should work correctly with Action Cable.

from anycable-rails.

palkan avatar palkan commented on June 18, 2024

This PR provides a fix: roidrage/lograge#304

from anycable-rails.

palkan avatar palkan commented on June 18, 2024

Yeah, I've updated the PR, so you can use my fork instead of a patch.

from anycable-rails.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.