Comments (9)
Added information to the Troubleshooting guide: https://docs.anycable.io/#/troubleshooting?id=authentication-fails-with-undefined-method-39protocol39-for-nilnilclass
from anycable-rails.
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.
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.
@palkan I just hit this today and found your fixed version in roidrage/lograge#310. Thanks!!
from anycable-rails.
Yep, that’s a lograge issue: roidrage/lograge#257 (comment)
Will add it to Troubleshooting.
from anycable-rails.
Please, display a information about this on frontpage or some wiki.
from anycable-rails.
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.
- 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)
- 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.
This PR provides a fix: roidrage/lograge#304
from anycable-rails.
Yeah, I've updated the PR, so you can use my fork instead of a patch.
from anycable-rails.
Related Issues (20)
- Does anycable truly depend on latest & greatest Ruby/Rails? HOT 2
- Rails 7 compatibility issue HOT 41
- log4r broken in development HOT 6
- Flutter app is connecting fine to wss, but actual subscribe is throwing unknown command type errors HOT 2
- Cannot call handle_open to handle JWT expiration HOT 2
- Permissions Error when Deploying AnyCable to Heroku HOT 11
- RPC memory usage - pods OOMkilled with 4GB allocated per pod HOT 4
- Anycable-rails and Seachkick together hangs the server HOT 2
- Tenant getting lost during identifier serialization HOT 3
- ActionController::RoutingError (No route matches [GET] "/cable")
- Devise authentication/sessions not working HOT 1
- What's the best way to close open connections on forking? HOT 5
- Issue with anycable-rpc crashing on start `terminate called after throwing an instance of 'std::logic_error'` HOT 2
- ActiveSupport::Logger.broadcast method is dropped HOT 8
- Issues with gRPC Communication between AnyCable Go and AnyCable Rails HOT 2
- ActionController::RoutingError (No route matches [GET] "/cable"): HOT 7
- reconnect option not forwarded in ActionCable::RemoteConnections::RemoteConnection#disconnect HOT 2
- Extract rubocop rules into separate gem HOT 1
- Whispering backport for Action Cable
- Automatically add Devise/Warden middleware
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anycable-rails.