actioncable在5分钟后与redis服务器断开连接

jjhzyzn0  于 2021-06-07  发布在  Redis
关注(0)|答案(0)|浏览(412)

我有一个railsapi,它将redis作为actioncable的适配器。
作为整个系统的一部分,我只使用actioncable进行简单的聊天。
一切都很完美,我可以订阅,发送信息,接收信息。问题出现在服务器启动5分钟后,我在redis gem中得到一个econnreset错误:connection lost(econnreset)(redis::connectionerror)
我已经三天没试着解决这个问题了,我试着改变redis服务器配置,我试着改变redis在rails应用程序上初始化的方式,我试着改变cable.yml配置,我试着改变actioncable配置,但似乎没有什么能解决这个问题,我已经没有主意了。
我也不能挽救这个例外,它只是打破了整个rails应用程序,这是另一件我无法解决的事情,这是如此令人沮丧。
顺便说一句,我正在开发环境中测试。
这是我的电缆配置:

  1. production:
  2. adapter: redis
  3. url: redis://192.168.1.6:6379
  4. development:
  5. adapter: redis
  6. url: redis://192.168.1.5:6379
  7. channel_prefix: ChatChannel
  8. timeout: 30
  9. max_conns: 8000
  10. max_persistent_conns: 8000
  11. test:
  12. adapter: async

这是我的redis初始化器:

  1. require 'redis'
  2. ## Added rescue condition if Redis connection is failed
  3. begin
  4. puts "CREATING NEW INSTANCE OF REDIS"
  5. $redis = Redis.new(
  6. :host => "192.168.1.5",
  7. :port => 6379,
  8. :reconnect_attempts => 10,
  9. :reconnect_delay => 1.5,
  10. :reconnect_delay_max => 10.0
  11. )
  12. $redis.ping
  13. rescue Errno::ECONNRESET => e
  14. puts "THERE WAS AN ERROR"
  15. puts e
  16. end

这是rails应用程序的输出:

  1. web_1 | Exiting
  2. web_1 | #<Thread:0x0000559ee244b1d8 /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:151 run> terminated with exception (report_on_exception is true):
  3. web_1 | /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:275:in `rescue in io': Connection lost (ECONNRESET) (Redis::ConnectionError)
  4. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:267:in `io'
  5. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:279:in `read'
  6. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:147:in `block (3 levels) in call_loop'
  7. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `loop'
  8. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `block (2 levels) in call_loop'
  9. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:248:in `block (2 levels) in process'
  10. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:389:in `ensure_connected'
  11. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:238:in `block in process'
  12. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:325:in `logging'
  13. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:237:in `process'
  14. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:145:in `block in call_loop'
  15. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:300:in `with_socket_timeout'
  16. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:144:in `call_loop'
  17. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:44:in `subscription'
  18. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:14:in `subscribe'
  19. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:3507:in `_subscription'
  20. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2326:in `block in subscribe'
  21. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  22. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  23. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  24. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  25. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2325:in `subscribe'
  26. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:84:in `block in listen'
  27. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:313:in `with_reconnect'
  28. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:75:in `block in with_reconnect'
  29. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  30. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  31. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  32. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  33. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:74:in `with_reconnect'
  34. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:81:in `without_reconnect'
  35. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:81:in `listen'
  36. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:155:in `block in ensure_listener_running'
  37. web_1 | /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:63:in `block in _read_from_socket': Connection reset by peer (Errno::ECONNRESET)
  38. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:52:in `loop'
  39. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:52:in `_read_from_socket'
  40. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:45:in `gets'
  41. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:378:in `read'
  42. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:280:in `block in read'
  43. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:268:in `io'
  44. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:279:in `read'
  45. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:147:in `block (3 levels) in call_loop'
  46. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `loop'
  47. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `block (2 levels) in call_loop'
  48. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:248:in `block (2 levels) in process'
  49. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:389:in `ensure_connected'
  50. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:238:in `block in process'
  51. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:325:in `logging'
  52. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:237:in `process'
  53. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:145:in `block in call_loop'
  54. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:300:in `with_socket_timeout'
  55. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:144:in `call_loop'
  56. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:44:in `subscription'
  57. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:14:in `subscribe'
  58. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:3507:in `_subscription'
  59. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2326:in `block in subscribe'
  60. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  61. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  62. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  63. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  64. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2325:in `subscribe'
  65. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:84:in `block in listen'
  66. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:313:in `with_reconnect'
  67. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:75:in `block in with_reconnect'
  68. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  69. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  70. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  71. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  72. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:74:in `with_reconnect'
  73. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:81:in `without_reconnect'
  74. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:81:in `listen'
  75. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:155:in `block in ensure_listener_running'
  76. web_1 | /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:275:in `rescue in io': Connection lost (ECONNRESET) (Redis::ConnectionError)
  77. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:267:in `io'
  78. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:279:in `read'
  79. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:147:in `block (3 levels) in call_loop'
  80. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `loop'
  81. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `block (2 levels) in call_loop'
  82. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:248:in `block (2 levels) in process'
  83. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:389:in `ensure_connected'
  84. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:238:in `block in process'
  85. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:325:in `logging'
  86. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:237:in `process'
  87. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:145:in `block in call_loop'
  88. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:300:in `with_socket_timeout'
  89. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:144:in `call_loop'
  90. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:44:in `subscription'
  91. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:14:in `subscribe'
  92. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:3507:in `_subscription'
  93. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2326:in `block in subscribe'
  94. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  95. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  96. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  97. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  98. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2325:in `subscribe'
  99. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:84:in `block in listen'
  100. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:313:in `with_reconnect'
  101. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:75:in `block in with_reconnect'
  102. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  103. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  104. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  105. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  106. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:74:in `with_reconnect'
  107. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:81:in `without_reconnect'
  108. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:81:in `listen'
  109. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:155:in `block in ensure_listener_running'
  110. web_1 | /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:63:in `block in _read_from_socket': Connection reset by peer (Errno::ECONNRESET)
  111. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:52:in `loop'
  112. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:52:in `_read_from_socket'
  113. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:45:in `gets'
  114. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/connection/ruby.rb:378:in `read'
  115. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:280:in `block in read'
  116. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:268:in `io'
  117. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:279:in `read'
  118. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:147:in `block (3 levels) in call_loop'
  119. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `loop'
  120. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:146:in `block (2 levels) in call_loop'
  121. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:248:in `block (2 levels) in process'
  122. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:389:in `ensure_connected'
  123. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:238:in `block in process'
  124. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:325:in `logging'
  125. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:237:in `process'
  126. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:145:in `block in call_loop'
  127. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:300:in `with_socket_timeout'
  128. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:144:in `call_loop'
  129. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:44:in `subscription'
  130. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/subscribe.rb:14:in `subscribe'
  131. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:3507:in `_subscription'
  132. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2326:in `block in subscribe'
  133. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  134. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  135. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  136. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  137. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:2325:in `subscribe'
  138. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:84:in `block in listen'
  139. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis/client.rb:313:in `with_reconnect'
  140. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:75:in `block in with_reconnect'
  141. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `block in synchronize'
  142. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `synchronize'
  143. web_1 | from /usr/local/lib/ruby/2.7.0/monitor.rb:202:in `mon_synchronize'
  144. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:69:in `synchronize'
  145. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:74:in `with_reconnect'
  146. web_1 | from /usr/local/bundle/gems/redis-4.2.5/lib/redis.rb:81:in `without_reconnect'
  147. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:81:in `listen'
  148. web_1 | from /usr/local/bundle/gems/actioncable-6.0.3.1/lib/action_cable/subscription_adapter/redis.rb:155:in `block in ensure_listener_running'
  149. nulimit-web_web_1 exited with code 1

这是redis服务器的输出:

  1. 1:M 08 Dec 2020 20:03:00.438 - Client closed connection

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题