Phoenix - client requested channel transport error - phoenix-framework

While running my Phoenix app, I suddenly noticed an error being logged:
The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"
It appears after starting the server with mix phoenix.server:
[info] Running MyApp.Endpoint with Cowboy using http://localhost:4000
21 Nov 13:47:19 - info: compiled 4 files into app.js, copied robots.txt in 2.3 sec
[error] The client's requested channel transport version "2.0.0" does not match server's version requirements of "~> 1.0"
and then continues to log the error message every 10 seconds or so, regardless of whether or not I'm making any requests to the server. Despite this, the app seems to run fine, but it'd be great to resolve this.
Can anyone shed any light on why this would've suddenly started happening, and what I can do to fix it?
Here's some config info from mix.exs:
def application do
[mod: {MyApp, []},
applications: [:phoenix, :phoenix_pubsub, :phoenix_html, :cowboy, :logger, :gettext,
:phoenix_ecto, :postgrex, :comeonin]]
end
defp deps do
[{:phoenix, "~> 1.2.1"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:cors_plug, "~> 1.1"},
{:comeonin, "~> 3.0"},
{:guardian, "~> 0.14"},
{:guardian_db, "~> 0.8.0"}]
end

Related

Action Cable is not working with rails 5

I am a beginner in Rails 5 and I am trying to implement web sockets in my app. I am trying to copy and run a test app at first and I figure out it is not working as it is not transmitting and receiving the data. received: (data) -> is never called. I also observed that it never gets connected with my redis server either (which I installed with brew). I am pasting all the code below. Thanks in advance.
//room.coffee
App.room = App.cable.subscriptions.create "RoomChannel",
connected: ->
# Called when the subscription is ready for use on the server
disconnected: ->
# Called when the subscription has been terminated by the server
received: (data) ->
alert(data['message'])
speak: (message) ->
#perform 'speak', message: message
room_chanel.rb
# Be sure to restart your server when you modify this file. Action
Cable runs in a loop that does not support auto reloading.
class RoomChannel < ApplicationCable::Channel
def subscribed
stream_from "room_channel"
end
def unsubscribed
# Any cleanup needed when channel is unsubscribed
end
def speak(data)
ActionCable.server.broadcast "room_channel", message: data['message']
end
end
Gemfile
source 'https://rubygems.org'
git_source(:github) do |repo_name|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/")
"https://github.com/#{repo_name}.git"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.0.2'
# Use postgresql as the database for Active Record
gem 'sqlite3'
# Use Puma as the app server
gem 'puma'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .coffee assets and views
gem 'coffee-rails', '~> 4.1.0'
# See https://github.com/rails/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
gem 'redis'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
gem 'turbolinks', '~> 5.x'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug', platform: :mri
end
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '~> 3.0.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
cable.yml
# Action Cable uses Redis by default to administer connections, channels, and sending/receiving messages over the WebSocket.
production:
adapter: redis
url: redis://localhost:6379/1
development:
adapter: redis
url: redis://localhost:6379/1
test:
adapter: redis
url: redis://localhost:6379/1
cable.coffee
# Action Cable provides the framework to deal with WebSockets in Rails.
# You can generate new channels where WebSocket features live using the rails generate channel command.
#
# Turn on the cable connection by removing the comments after the require statements (and ensure it's also on in config/routes.rb).
#
#= require action_cable
#= require_self
#= require_tree ./channels
#
#App ||= {}
App.cable = ActionCable.createConsumer()
You might try to use Action Cable without Redis (since Redis is not strictly required for Action Cable):
development:
adapter: async
test:
adapter: async
production:
adapter: redis
url: redis://localhost:6379/1
But this probably is not the origin of your problem. Your room.coffee lacks some speak-calling code. Add to room.coffee something like this:
$ ->
$('#send_form').submit (event)->
App.room.speak event.currentTarget['message'].value
event.currentTarget['message'].value = ""
event.preventDefault()
false
Here's a template:
<div class="jumbotron">
<form id="send_form">
<label>Message:</label>
<input id="message" type="text" data-behavior="room_speaker">
<br>
<input type="submit" data-behavior="room_speaker">
</form>
</div>

Heroku Production - ActionView::Template::Error (undefined method `directory' for #<Sprockets::Manifest:number>)

We have a react-rails app. Unfortunately, the app works on local development but not when deployed to heroku. When going to our default path on the app, we get the following error:
ActionView::Template::Error (undefined method 'directory' for #<Sprockets::Manifest:0x007fef13200aa8>)
We've figured out that it happens at this line in our view:
<%= react_component('NavBar', {}, {prerender: true}) %>
A few things about our app:
It uses browserify to compile our js.jsx.
We precompile using RAILS_ENV=production bundle exec rake assets:precompile after deleting the public/assets folder.
Works locally with both rails s and foreman start
We are using boostrap-sprockets. Even when removed, we still have this issue.
Here is our npm dependencies:
"dependencies": {
"browserify": "^10.2.4",
"browserify-incremental": "^1.5.0",
"classnames": "^2.2.3",
"reactify": "^1.1.0"
}
Here is our Gemfile
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'rails-api'
gem 'spring', :group => :development
gem 'active_model_serializers', '~> 0.10.0.rc1'
gem 'pg'
gem 'devise'
gem 'puma'
gem 'twitter'
gem 'react-rails', '~> 1.0'
gem 'browserify-rails', '~> 0.9.1'
gem 'bootstrap-sass', '~> 3.2.0'
gem 'sass-rails', '~> 5.0', '>= 5.0.4'
gem 'autoprefixer-rails'
group :test do
gem 'rspec-rails'
gem 'pry'
gem 'faker'
gem 'webmock'
end
group :development, :test do
gem 'factory_girl_rails'
end
group :production do
gem 'uglifier'
gem 'rails_12factor'
gem 'rspec'
end
ruby '2.2.4'
We would appreciate all help.
The solution from hours of searching on StackOverflow and github issues seems to be to remove
//= require react_ujs
from your application.js in your assets folder.
I ran into this same issue just today and followed the suggestions in: https://github.com/reactjs/react-rails/issues/443#issuecomment-180544359. I was still running into an error so for now I modified my heroku configurations (config/environments/staging.rb & config/environments/production.rb) to use
config.assets.compile = true
for now and server-side rendering worked fine. The react-rails folks said they have a pull request completed to fix this issue but I dont think it has been released yet.
Potentially relevant: rake assets:precompile undefined method directory? for nil:NilClass
This is an error that occurs when the Rails asset compiler (Sprockets) cannot find a directory that you've specified as the location of an asset for your project. My suggestion is to make sure that all your assets are being successfully deployed to heroku, and then check that your paths are set up correctly when you reference assets in your project for inclusion in a page.
Also see Eric C's answer pertaining to React-Rails specifically.
There was a bug in react-rails 1.6.0 which should be fixed in 1.6.1
Here's the patch:
https://github.com/reactjs/react-rails/pull/478
If the latest version doesn't work for you, please open an issue on the react-rails repo!

Where do I start to investigate when phoenix live reload stops working after upgrading to Phoenix 1.0?

I just upgraded my project to Phoenix 1.0. For some reason phoenix live reload stopped working when I changed my files. Is there a place where I should look first to try to gain some insight on why it stopped working? Here is what my mix.exs looks like:
defp deps do
[{:phoenix, "~> 1.0"},
{:phoenix_html, "~> 2.1"},
{:phoenix_live_reload, "~> 1.0"},
{:cowboy, "~> 1.0"},
{:shouldi, only: :test},
{:meck, "~> 0.8.3"}]
end
Have you checked in your config/dev.exs file and seen (similar):
# Watch static and templates for browser reloading.
config :polyvox, Polyvox.Endpoint,
live_reload: [
patterns: [
~r{priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$},
~r{web/views/.*(ex)$},
~r{web/templates/.*(eex)$}
]
]

Rspec suite fails running on AWS Ubuntu with ECONNREFUSED - but each test passes individually

We are trying to migrate our rails build from a local network server to an AWS EC2 instance running Ubuntu. The test suite works fine on all the developers machines (combination of mac and ubuntu) and the old build server (linux) but refuses to pass on the amazon instance.
The symptom is:
An error occurred in an after hook
Errno::ECONNREFUSED: Connection refused - connect(2)
occurred at /home/ubuntu/.rvm/rubies/ruby-2.0.0-p481/lib/ruby/2.0.0/net/http.rb:878:in 'initialize'
which is repeated a bunch of times. There is no error logged before this one.
However this issue only occurs when running multiple tests together (eg, bundle exec rspec) - when I run each test individually they all pass. Locally none of the dev team have seen this issue before.
Our tests use Selenium and Firefox which should run headless on ubuntu using Xvfb. We also use WebMock for some tests.
I have researched this issue for a day or two now and tried everything I can think of, to no avail. I have checked the versions of firefox and all the gems installed are the same on aws as locally.
My gemfile and spec_helper are below. I have investigated the firefox and xvfb installation, but because each test is able to pass individually I feel the system is generally ok ... but clearly something is not happy.
Version details
ruby 2.0.0p481
rails 3.2.16
rspec 2.14.8
firefox 29
ubuntu 14.04
Gemfile
source 'https://rubygems.org'
#Base gems
gem 'rails', '~> 3.2.16'
gem 'sass-rails'
gem 'bcrypt-ruby', '~> 3.0.0'
gem 'faker', '~> 1.2.0'
gem 'jquery-rails', '~> 3.0.0'
#gem 'jquery-rails', '~> 2.1.4'
gem 'jquery-migrate-rails'
# threading gem
gem 'sucker_punch', '~> 1.0'
gem 'mixpanel-ruby'
# Mongo gems
gem 'mongoid', '~> 3.1.6'
gem 'bson_ext', '~> 1.9.2'
gem 'origin', '~> 1.1.0'
gem 'mongoid-enum' , '~> 0.1.1'
#filemaker gem
#gem 'ginjo-rfm', '~> 2.1.7'
# data gird gem
gem 'datagrid', '1.0.5'
# New Relic and Engine Yard Gems
gem 'ey_config', '~> 0.0.6'
gem 'newrelic_rpm'
#Authorsiation
gem 'cancan', '~> 1.6.10'
#paging
gem 'kaminari', '~> 0.15'
#client side validation
gem 'jquery-validation-rails'
#file upload
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
gem 'rmagick', '~> 2.13.2'
gem 'fog' , '~> 1.19.0'
gem 'unf', '~> 0.1.3'
gem 'remotipart', '~> 1.2'
gem 'listen', '2.7.6'
# reports for jenkins - see if having it here allows engineyard to deploy
gem 'ci_reporter', '1.9.1'
#NOTE YOU MUST INSTALL IMG MAGIC IF bundle install fails
#http://www.imagemagick.org/script/binary-releases.php#unix
#sudo apt-get install libmagickwand-dev imagemagick
gem 'timecop', '~> 0.7.1'
#file upload
gem 'jquery-fileupload-rails', '~> 0.4.1'
gem 'jquery-cookie-rails', '~> 1.3.1'
#configuring Rails
gem 'figaro'
#History tracking
gem 'mongoid-history'
gem 'nav_lynx'
#modal window requirements
gem 'jquery-ui-rails'
gem 'jquery-modal-rails'
gem 'itree'
gem 'lumberjack'
gem 'newrelic_moped'
group :development, :test do
gem 'rspec-rails', '~> 2.14.0'
gem 'guard-rspec', '~> 4.2.0'
gem 'guard-spork', '~> 1.5.1'
gem 'childprocess', '0.3.9'
gem 'spork', '~> 1.0.0rc4'
gem 'spork-rails', '~> 4.0.0'
gem 'bullet'
end
group :development, :staging do
gem 'rack-mini-profiler'
end
#Used to annotate model files generated
group :development do
gem 'annotate', '~> 2.6.0'
gem 'letter_opener', '~> 1.1.2'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'coffee-rails', '~> 3.2.2'
gem 'uglifier', '~> 2.3.2'
end
group :test do
gem 'capybara', '~> 2.2.1'
gem 'selenium-webdriver', '2.39.0'
gem 'database_cleaner', '~> 1.2.0'
#needs sudo apt-get install xvfb
gem 'headless'
#static security analysis tool
gem 'brakeman', :require => false
#generating mock objects in tests
gem 'factory_girl_rails', '~> 4.3.0'
gem 'webmock', '~> 1.16.0'
#for windows
gem 'rb-fchange' if /win32/ =~ RUBY_PLATFORM
gem 'rb-notifu' if /win32/ =~ RUBY_PLATFORM
gem 'win32console' if /win32/ =~ RUBY_PLATFORM
#for linux
gem 'rb-inotify', '~> 0.9.2' if /linux/ =~ RUBY_PLATFORM
gem 'libnotify', '~> 0.8.2' if /linux/ =~ RUBY_PLATFORM
#for macosx
gem 'growl', '~> 1.0.3' if /darwin/ =~ RUBY_PLATFORM
gem 'rb-fsevent', '~> 0.9.3' if /darwin/ =~ RUBY_PLATFORM
# for rcov in Jenkins
gem 'simplecov'
gem 'simplecov-rcov'
#additional matches for rspect
gem 'shoulda-matchers', '~> 2.5.0'
#open browser on demand to debug tests
gem 'launchy'
#http rest client
gem 'rest-client', '~> 1.6.7'
gem 'show_me_the_cookies'
end
spec_helper.rb
require 'rubygems'
require 'spork'
require 'webmock/rspec'
require 'sucker_punch'
require 'sucker_punch/testing/inline'
Spork.prefork do
if ENV["RUBYMINE_HOME"]
$:.unshift(File.expand_path("rb/testing/patch/common", ENV["RUBYMINE_HOME"]))
$:.unshift(File.expand_path("rb/testing/patch/bdd", ENV["RUBYMINE_HOME"]))
end
# setup simple cov for Jenkins
require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start 'rails'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.include ShowMeTheCookies
# Include Factory Girl syntax to simplify calls to factories
config.include FactoryGirl::Syntax::Methods
#Don't run any tests that contain :skip_test => true
config.filter_run_excluding :skip_test => true
# If true, the base class of anonymous controllers will be inferred
# automatically. This will be the default behavior in future versions of
# rspec-rails.
config.infer_base_class_for_anonymous_controllers = false
# Run specs in random order to surface order dependencies. If you find an
# order dependency and want to debug it, you can fix the order by providing
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
config.include Capybara::DSL
config.before(:suite) do
Headless.new.start
end
config.before(:all) do
#manually clear database
YearDates.destroy_all
CoursePlan.destroy_all
Topic.destroy_all
FactoryGirl.create(:stub_year_dates)
end
config.after(:all) do
Timecop.return
end
#Mongoid database cleaner
config.before(:suite) do
DatabaseCleaner[:mongoid, {:connection => :unit_test}].clean_with(:truncation)
DatabaseCleaner[:mongoid, {:connection => :unit_test}].strategy = :truncation
end
config.before(:each) do
new_time = Time.local(2014, 1, 20) #week two of the year
Timecop.travel(new_time)
Timecop.baseline = new_time
DatabaseCleaner[:mongoid, {:connection => :unit_test}].start
FactoryGirl.create(:stub_year_dates) #recreate this on each test as it is needed all the time, but edited sometimes
#need to ensure these exist before the other factories are called
FactoryGirl.create(:english_subject)
FactoryGirl.create(:chemistry_subject)
FactoryGirl.create(:maths_ext_2_subject)
FactoryGirl.create(:maths_ext_1_tutorials_only_subject)
end
config.after(:each) do
Timecop.return_to_baseline
DatabaseCleaner[:mongoid, {:connection => :unit_test}].clean
end
Capybara.default_wait_time = 5 #wait longer for ajax requests
end
end
Spork.each_run do
# This code will be run each time you run your specs.
FactoryGirl.reload
end
WebMock.allow_net_connect!
I would greatly appreciate any assistance!
update
I have determined that the results are inconsistent between test runs. At first I thought it was the same each time, but the number of tests failing varies each run. I thought I had fixed the problem when all the tests passed except one, but the next run it was back to over a hundred failures.
update 2
Upon closer inspection (oops) I have discovered there were some tests failing with a different error the the majority. Instead of ECONNREFUSED, they are reporting 'End Of File Reached'. When I disabled these tests (5 in total) the remaining tests pass reliably. I suspect that xvfb is encountering some javascript or ajax related error, which is then preventing any of the following tests from passing. We are now working on diagnosing what is happening in these tests that is causing the failure.
File this one under 'not sure'. We ended up running up a new AWS server and setting it up again from scratch, and this time it worked fine. Some where suspect an issue with the javascript driver, possibly permissions related, but it is not worth our time investigating.

Heroku with ruby 1.9.3 causing many different crashes

I go to redeploy my heroku apps with a new gem in Gemfile and it crashes on startup
/app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.3/lib/active_support/dependencies.rb:251:in `require': libruby.so.1.9: cannot open shared object file: No such file or directory - /app/vendor/bundle/ruby/1.9.1/gems/bcrypt-ruby-3.0.1/lib/bcrypt_ext.so (LoadError)
This is happening no matter what branch I deploy (old stable ones...) and only fixes by doing a heroku rollback.
I believe this is caused by heroku recently updating their ruby 1.9.3 because I was having this issue Heroku app crashes with 'libruby.so.1.9: cannot open shared object file' . Removing the nokogiri gem stopped the exception I was getting but then there's still this. More similar errors occur when I add new gems.
The whole problem was solved by deploying to a new heroku app but that's not something I can just do on my production server.
Any ideas on fixing the issue or somehow "refreshing" my app?
my gemfile:
source "https://rubygems.org"
ruby "1.9.3"
gem "rails", "3.2.3"
gem "thin"
# Bundle edge Rails instead:
# gem "rails", :git => "git://github.com/rails/rails.git"
gem "mongoid"
gem "devise"
gem "haml"
gem "sass"
gem "exceptional"
gem "kaminari"
gem "mongoid_search"
#gem "nokogiri"
gem "bson_ext"
gem "heroku-mongo-backup"
gem "aws-s3"
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem "haml-rails", "~> 0.3.4"
gem "sass-rails", "~> 3.2.3"
gem "coffee-rails", "~> 3.2.1"
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem "therubyracer", :platform => :ruby
gem "uglifier", ">= 1.0.3"
end
gem "jquery-rails"
group :test do
gem "mongoid-rspec"
end
# To use ActiveModel has_secure_password
# gem "bcrypt-ruby", "~> 3.0.0"
# To use Jbuilder templates for JSON
# gem "jbuilder"
# Use unicorn as the app server
# gem "unicorn"
# Deploy with Capistrano
# gem "capistrano"
# To use debugger
# gem "ruby-debug19", :require => "ruby-debug"
#
group :development do
gem "letter_opener"
end
Just FYI,
After contacting the Heroku support about this issue, you should follow these 3 simple steps:
Install this heroku-repo plugin: heroku plugins:install https://github.com/lstoll/heroku-repo.git
Run the following command: heroku repo:purge_cache
Deploy your app again.
Hope that helps!
This happened to me yesterday as well, was definitely something to do with Heroku.
I found fix and discussion on Twitter: https://twitter.com/bcardarella/status/256822171979100161
Just force-clear the gem file cache(clear gemfile, deploy, restore and deploy) and the app would start smoothly again.

Resources