无法通过WSL启动Rails的本地服务器。

huangapple go评论102阅读模式
英文:

Cannot start local server with Rails via WSL

问题

我尝试更新我的Rails应用程序,我认为问题可能出现在这里,因为我无法启动服务器。我已经尝试切换Ruby版本和降级Rails,但在某个地方卡住了,一直收到相同的错误。

我相信问题出在这里:日志的最后一行显示了与Puma有关的问题。

这个Gist中,你可以找到我的Gemfile和Gemfile.lock

  1. rails s
  2. => 启动Puma
  3. => Rails 6.0.2.1应用程序正在开发中启动
  4. => 运行 `rails server --help` 以获取更多启动选项
  5. Puma以单模式启动...
  6. * 版本4.3.1ruby 2.6.3-p62),代号:神秘的旅行者
  7. * 最小线程数:5,最大线程数:5
  8. * 环境:开发
  9. 退出
  10. 回溯(最近的调用最后):
  11. 31: 来自bin/rails:4:in `<main>'
  12. 30: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require'
  13. 29: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency'
  14. 28: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require'
  15. 27: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require'
  16. 26: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi'
  17. 25: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register'
  18. 24: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi'
  19. 23: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require'
  20. 22: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `<main>'
  21. 21: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke'
  22. 20: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform'
  23. 19: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
  24. 18: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
  25. 17: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
  26. 16: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `perform'
  27. 15: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `tap'
  28. 14: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform'
  29. 13: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:39:in `start'
  30. 12: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/rack-2.0.8/lib/rack/server.rb:297:in `start'
  31. 11: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/rack/handler/puma.rb:73:in `run'
  32. 10: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run'
  33. 9: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/single.rb:98:in `run'
  34. 8: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/runner.rb:161:in `load_and_bind'
  35. 7: /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:90:in `parse'
  36. 6: 从/home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:90:
  37. <details>
  38. <summary>英文:</summary>
  39. I tried updating my Rails app and I believe here is the problem somewhere since I am not able to start the server. I already tried to switch Ruby-Versions and downgrade Rails but somewhere I got stuck and keep getting the same Error.
  40. &gt; .rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:233:in `setsockopt&#39;: Invalid argument - setsockopt(2) (Errno::EINVAL)
  41. I believe here comes the problem: The very last line of the log shows issues with Puma.
  42. In [this Gist you can find my Gemfile and Gemfile.lock][1]
  43. ```ruby
  44. rails s
  45. =&gt; Booting Puma
  46. =&gt; Rails 6.0.2.1 application starting in development
  47. =&gt; Run `rails server --help` for more startup options
  48. Puma starting in single mode...
  49. * Version 4.3.1 (ruby 2.6.3-p62), codename: Mysterious Traveller
  50. * Min threads: 5, max threads: 5
  51. * Environment: development
  52. Exiting
  53. Traceback (most recent call last):
  54. 31: from bin/rails:4:in `&lt;main&gt;&#39;
  55. 30: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `require&#39;
  56. 29: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:291:in `load_dependency&#39;
  57. 28: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/activesupport-6.0.2.1/lib/active_support/dependencies.rb:325:in `block in require&#39;
  58. 27: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:30:in `require&#39;
  59. 26: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:21:in `require_with_bootsnap_lfi&#39;
  60. 25: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/loaded_features_index.rb:92:in `register&#39;
  61. 24: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `block in require_with_bootsnap_lfi&#39;
  62. 23: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/bootsnap-1.4.5/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:22:in `require&#39;
  63. 22: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands.rb:18:in `&lt;main&gt;&#39;
  64. 21: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/command.rb:46:in `invoke&#39;
  65. 20: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/command/base.rb:69:in `perform&#39;
  66. 19: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch&#39;
  67. 18: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command&#39;
  68. 17: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/thor-0.20.3/lib/thor/command.rb:27:in `run&#39;
  69. 16: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `perform&#39;
  70. 15: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:138:in `tap&#39;
  71. 14: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:147:in `block in perform&#39;
  72. 13: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.1/lib/rails/commands/server/server_command.rb:39:in `start&#39;
  73. 12: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/rack-2.0.8/lib/rack/server.rb:297:in `start&#39;
  74. 11: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/rack/handler/puma.rb:73:in `run&#39;
  75. 10: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/launcher.rb:172:in `run&#39;
  76. 9: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/single.rb:98:in `run&#39;
  77. 8: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/runner.rb:161:in `load_and_bind&#39;
  78. 7: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:90:in `parse&#39;
  79. 6: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:90:in `each&#39;
  80. 5: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:106:in `block in parse&#39;
  81. 4: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:222:in `add_tcp_listener&#39;
  82. 3: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:222:in `each&#39;
  83. 2: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:223:in `block in add_tcp_listener&#39;
  84. 1: from /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:233:in `add_tcp_listener&#39;
  85. /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb:233:in `setsockopt&#39;: Invalid argument - setsockopt(2) (Errno::EINVAL)

Thanks for any help in advance! Denny

答案1

得分: 1

找到了临时解决方案。
示例如下:
在文件 /home/%username%/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/binder.rb 或者在您的情况下是 /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb
大约在第233行:

  1. #
  2. def add_tcp_listener(host, port, optimize_for_latency=true, backlog=1024)
  3. if host == &quot;localhost&quot;
  4. loopback_addresses.each do |addr|
  5. add_tcp_listener addr, port, optimize_for_latency, backlog
  6. end
  7. return
  8. end
  9. host = host[1..-2] if host and host[0..0] == &#39;[&#39;
  10. # monkey patch starts here
  11. host = &#39;127.0.0.1&#39;
  12. port = 3000
  13. # monkey patch ends here
  14. s = TCPServer.new(host, port)
  15. # if optimize_for_latency
  16. s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
  17. # end
  18. # s.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
  19. s.listen backlog
  20. @connected_port = s.addr[1]
  21. @ios &lt;&lt; s
  22. s
  23. end

现在一切正常,但我们仍然需要正确解决此问题。
这是一个常见的WSL问题:https://github.com/microsoft/WSL/issues/1419

英文:

found the temporal solution.
Example is below:
in file /home/%username%/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/puma-4.3.1/lib/puma/binder.rb or in your case /home/chocolope/.rvm/gems/ruby-2.6.3/gems/puma-4.3.1/lib/puma/binder.rb
around row 233:

  1. #
  2. def add_tcp_listener(host, port, optimize_for_latency=true, backlog=1024)
  3. if host == &quot;localhost&quot;
  4. loopback_addresses.each do |addr|
  5. add_tcp_listener addr, port, optimize_for_latency, backlog
  6. end
  7. return
  8. end
  9. host = host[1..-2] if host and host[0..0] == &#39;[&#39;
  10. # monkey patch starts here
  11. host = &#39;127.0.0.1&#39;
  12. port = 3000
  13. # monkey patch ends here
  14. s = TCPServer.new(host, port)
  15. # if optimize_for_latency
  16. s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
  17. # end
  18. # s.setsockopt(Socket::SOL_SOCKET,Socket::SO_REUSEADDR, true)
  19. s.listen backlog
  20. @connected_port = s.addr[1]
  21. @ios &lt;&lt; s
  22. s
  23. end

now everything works, but we still need the right way to fix this issue

this is a common WSL problem: https://github.com/microsoft/WSL/issues/1419

答案2

得分: 0

我遇到了类似的问题,使用以下配置:

WSL: 1,Ruby: 2.5.0,Rails: 4.2.1,以及Puma: 3.8.0

当我发送GET请求时,Rails服务器正常工作,但我一直收到以下错误:

  1. Read error: #&lt;Errno::ENOPROTOOPT: Protocol not available - getsockopt(2)&gt;
  2. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:124:in `getsockopt&#39;
  3. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:124:in `closed_socket?&#39;
  4. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:563:in `handle_request&#39;
  5. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:425:in `process_client&#39;
  6. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:289:in `block in run&#39;
  7. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread&#39;

我为了解决这个问题付出了很多努力,甚至尝试了上面的解决方案,但都没有成功。

最后,我找到了一个简单的解决方法,只需要将Puma从3.8升级到3.12+,然后问题就完美解决了。

英文:

I was having a similar issue with

WSL: 1, Ruby: 2.5.0, Rails: 4.2.1, and Puma: 3.8.0

my rails s was working i was getting the follwoing error when ever i send a Get request:

  1. Read error: #&lt;Errno::ENOPROTOOPT: Protocol not available - getsockopt(2)&gt;
  2. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:124:in `getsockopt&#39;
  3. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:124:in `closed_socket?&#39;
  4. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:563:in `handle_request&#39;
  5. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:425:in `process_client&#39;
  6. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/server.rb:289:in `block in run&#39;
  7. /home/abr/.rvm/gems/ruby-2.5.0@helpy/gems/puma-3.8.1/lib/puma/thread_pool.rb:120:in `block in spawn_thread&#39;

I struggle a lot for fixing that issue even I try the above solution but that didn't work either.

at last, I found a simple solution that I need to update my Pum from 3.8 to 3.12+ and it works perfectly for me.

huangapple
  • 本文由 发表于 2020年1月6日 20:27:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/59612138.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定