尝试修复机架 lint 错误和 GET /cable 上的 500
trying to fix a rack lint error and 500 on GET /cable
我在我们的 rails 后端和 angularjs 前端使用 angular-actioncable 实现了动作电缆,一切都按预期工作,客户端到服务器的 websocket 连接已建立,广播和接收正在工作,但当我启动应用程序时,它总是在 GET /cable 上抛出机架 lint 错误和 500 错误,
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
我将照片放在架子上 gem,它 returns 状态为 -1,找不到任何关于 -1 含义的文档。
谢谢
对于其他遇到同样问题的人,原因是 Rack 在将 http 协议升级到 websockets 时进行了套接字劫持,并且 returns a -1 rack lint 没有将其视为有效的 http 状态,在开发中,您可以设置 RACK_ENV=deployment RAILS_ENV=development
进行测试,您可以使用简单的初始化程序对 headers/status 检查动作电缆进行存根,更多详细信息 here,来自上面 link 的初始化程序,
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
我在我们的 rails 后端和 angularjs 前端使用 angular-actioncable 实现了动作电缆,一切都按预期工作,客户端到服务器的 websocket 连接已建立,广播和接收正在工作,但当我启动应用程序时,它总是在 GET /cable 上抛出机架 lint 错误和 500 错误,
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
我将照片放在架子上 gem,它 returns 状态为 -1,找不到任何关于 -1 含义的文档。
谢谢
对于其他遇到同样问题的人,原因是 Rack 在将 http 协议升级到 websockets 时进行了套接字劫持,并且 returns a -1 rack lint 没有将其视为有效的 http 状态,在开发中,您可以设置 RACK_ENV=deployment RAILS_ENV=development
进行测试,您可以使用简单的初始化程序对 headers/status 检查动作电缆进行存根,更多详细信息 here,来自上面 link 的初始化程序,
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