Home > Blockchain >  trying to fix a rack lint error and 500 on GET /cable
trying to fix a rack lint error and 500 on GET /cable

Time:03-02

I implemented action cable in our rails backend and angularjs frontend using angular-actioncable, it is all working as expected, client to server websocket connection is established and broadcasts and receives are working but when I start the app, it always throws a rack lint error and a 500 error on GET /cable,

09:33:10 web.1       | Rack::Lint::LintError: Status must be >=100 seen as integer
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:25:in `assert'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:675:in `check_status'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:70:in `_call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/lint.rb:42:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/show_exceptions.rb:23:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/common_logger.rb:38:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/sinatra-2.1.0/lib/sinatra/base.rb:253:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/chunked.rb:98:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rack-2.2.3/lib/rack/content_length.rb:17:in `call'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:632:in `process_client'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:728:in `worker_loop'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:548:in `spawn_missing_workers'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/lib/unicorn/http_server.rb:144:in `start'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/unicorn-5.7.0/bin/unicorn:128:in `<top (required)>'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `load'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/bin/unicorn:23:in `<top (required)>'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `load'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:63:in `kernel_load'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli/exec.rb:28:in `run'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:476:in `exec'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:30:in `dispatch'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/cli.rb:24:in `start'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:46:in `block in <top (required)>'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/2.7.0/bundler/friendly_errors.rb:123:in `with_friendly_errors'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/bundler-2.1.4/libexec/bundle:34:in `<top (required)>'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `load'
09:33:10 web.1       |  /home/leonidas/.asdf/installs/ruby/2.7.3/bin/bundle:23:in `<main>'
09:33:10 web.1       | 127.0.0.1 - - [11/Feb/2022:09:33:10  1100] "GET /cable/ HTTP/1.1" 500 3356 0.4378

I put prints in the rack gem and it returns a status of -1, can't find any docs on what -1 means.

Thanks

CodePudding user response:

For anyone else having the same issue, the reason was Rack does socket highjacking while upgrading the http protocol to websockets and returns a -1 which the rack lint doesn't see as a valid http satus, in development you can set RACK_ENV=deployment RAILS_ENV=development to test and you can stub the headers/status check for action cable with a simple initializer, more details here, initializer from the link above,

class ::Rack::Lint
  alias check_status_orig check_status
  alias check_headers_orig check_headers
  alias check_content_type_orig check_content_type
  alias check_content_length_orig check_content_length
  alias check_hijack_orig check_hijack
  alias _call_orig _call

  def _call(env)
    @web_socket = env['REQUEST_PATH'] == '/cable'
    _call_orig(env)
  end

  def check_status(status)
    return if @web_socket
    check_status_orig(status)
  end

  def check_headers(headers)
    return if @web_socket
    check_headers_orig(headers)
  end

  def check_content_type(status, headers)
    return if @web_socket
    check_content_type_orig(status, headers)
  end

  def check_content_length(status, headers)
    return if @web_socket
    check_content_type_orig(status, headers)
  end

  def check_hijack(env)
    # Don't know why, but HijackWrapper break WebSocket!
    return if @web_socket
    check_hijack_orig(env)
  end
end
  • Related