Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Vladimir Dementyev
    @palkan
    Hi! Do you expect a broadcasted message being received by a client, which executes #subscribed callback? Or by other clients?
    Eugene Burmakin
    @Freika
    I broadcast it to chatroom so I expect all clients subscribed to it to receive the message
    Vladimir Dementyev
    @palkan
    • Check your Redis settings for AnyCable RPC process (AnyCable.config.to_redis_params)
    • Make sure RAILS_ENV is configured correctly
    Eugene Burmakin
    @Freika
    Hm, I don't have this option in project code
    Vladimir Dementyev
    @palkan
    The currently subscribing client may not receive this message, because subscribing and broadcasting are happening concurrently (the same is true for plain Action Cable)
    Eugene Burmakin
    @Freika
    and RAILS_ENV is production
    Vladimir Dementyev
    @palkan
    Try to call pp AnyCable.config somewhere in initializer and check the output for AnyCable process
    Another thing to check is the value of ActionCable.server.pubsub
    Eugene Burmakin
    @Freika
    irb(main):002:0> pp AnyCable.config.to_redis_params {:url=>"redis://192.168.72.98:20318/0"} => {:url=>"redis://192.168.72.98:20318/0"} irb(main):003:0> ActionCable.server.pubsub => #<ActionCable::SubscriptionAdapter::AnyCable:0x000055d817c5e898>
    irb(main):004:0> pp AnyCable.config
    #<AnyCable::Config
      config_name="anycable"
      env_prefix="ANYCABLE"
      values:
        rpc_host => "127.0.0.1:50051" (type=defaults),
        rpc_pool_size => 30 (type=defaults),
        rpc_max_waiting_requests => 20 (type=defaults),
        rpc_poll_period => 1 (type=defaults),
        rpc_pool_keep_alive => 1 (type=defaults),
        rpc_server_args =>,
        broadcast_adapter => "redis" (type=yml path=config/anycable.yml),
        redis_url => "redis://192.168.72.98:20318/0" (type=defaults),
        redis_sentinels => nil (type=defaults),
        redis_channel => "__anycable__" (type=yml path=config/anycable.yml),
        http_broadcast_url => "http://localhost:8090/_broadcast" (type=defaults),
        http_broadcast_secret => nil (type=defaults),
        log_file => nil (type=defaults),
        log_level => :info (type=defaults),
        log_grpc => false (type=yml path=config/anycable.yml),
        debug => false (type=defaults),
        http_health_port => nil (type=defaults),
        http_health_path => "/health" (type=defaults),
        version_check_enabled => true (type=defaults),
        access_logs_disabled => true (type=yml path=config/anycable.yml),
        persistent_session_enabled => false (type=defaults)>
    Vladimir Dementyev
    @palkan
    Does redis_url and redis_channel matches the ones you have configured for AnyCable-Go?
    Eugene Burmakin
    @Freika
    Yes, they are the same
    Vladimir Dementyev
    @palkan
    Try running anycable-go with -debug switch and see whether you have logs like “Incoming pubsub message”
    Eugene Burmakin
    @Freika
    Yes, see these messages
    Alex Dubov
    @adubov1
    @palkan all my users will log onto a subdomain that represents their organization. so there will be multiple subdomains and multiple users on each.
    sakthigurunathan
    @sakthigurunathan
    @palkan If I want the metrics for the number of GRPC method calls currently happening or in queue, shall I rely on the goroutines_num ?
    Vladimir Dementyev
    @palkan
    Nope, active/pending RPC calls do not affect the number of goroutines; the upcoming rpc_pending_num will tall you about the current queue size; if it's not zero, then the number of active calls is equal to the configured RPC concurrency
    Vladimir Dementyev
    @palkan
    @adubov1 I found this: rails/rails#10024 ; it's old but probably related; have you tried running the same app on a localhost, for example?
    sakthigurunathan
    @sakthigurunathan
    @palkan rpc_pending_num is 0 in most of the cases and I see a pattern in goroutines_num when goroutines_num increases (say 2500) then I see a lag in the broadcasting of the messages. What does goroutines_num denotes?
    Vladimir Dementyev
    @palkan
    It’s O(N) of the number of active connections; what is the value of clients_num? They should have similar patterns.
    Broadcasting lag could increase either when you have a lot of messages to broadcast or when you have a lot of clients. Currently, only a single broadcasting could happen at a time; usually, it’s pretty fast and only becomes noticeable when the throughput or the number of subscribed clients is high.
    Alex Dubov
    @adubov1
    @palkan the fix mentioned in #10024, along with using cookie store, worked for me! thank you so much for your help! :)
    sakthigurunathan
    @sakthigurunathan
    @palkan Really appreciate for your info on go_routines_num. As you said, I could see a pattern between clients num and goroutines_num. If there is 1 active connection and there are 2 goroutines corresponding to that connection. Is there a way for us to identify how many messages are pending to broadcast?
    Vladimir Dementyev
    @palkan
    No, not yet. I will take a look whether it could be implemented quickly and shipped in a patch release.
    sakthigurunathan
    @sakthigurunathan
    Thanks @palkan
    John Shen
    @johnshen64_gitlab
    Hi, I have a question about https://github.com/anycable/anycable-rack-server which says using with rail, Add gem "anycable-rack-server" to you Gemfile and make sure your Action Cable adapter is set to :any_cable. That's it! We automatically start AnyCable Rack server for your at /cable path. but I am getting this error: WebSocket connection to 'ws://localhost:3334/cable' failed: Error during WebSocket handshake: Unexpected response code: 400 here is my config/environments/test.rb changes:
     # Enforce AnyCable patches to make it possible to use any_cable adapter for system tests
      require "anycable/rails/actioncable/connection"
      # TEMP: Remove me after final anycable 1.0.0 release
      require "anycable/rack/version"
    
      # Specify AnyCable WebSocket server URL to use by JS client
      config.action_cable.url = "ws://localhost:3334/cable"
      # Disable built-in Action Cable
      config.action_cable.mount_path = nil
      config.action_cable.disable_request_forgery_protection = true
      # Run AnyCable Rack server at a custom path
      config.any_cable_rack.mount_path = "/cable"
    Vladimir Dementyev
    @palkan
    Hey! In this case, you don’t need config.action_cable.url, the Rack WebSocket server is running within the main web server and accessible at the /cable path, which is the Rails default config value
    John Shen
    @johnshen64_gitlab

    Oh, I see, Thanks! However when I removed the config.action_cable.url line I got this in my rails app

    ActionView::Template::Error: No Action Cable URL configured -- please configure this at config.action_cable.url
        app/views/layouts/application.html.erb:4
        app/controllers/users/sessions_controller.rb:11:in `new'

    so I changed it to config.action_cable.url = "/cable" but got the same error.
    also, is websocket connection to ws://localhost:3334/cable correct? or should that be changed to something else?

    John Shen
    @johnshen64_gitlab

    so I just do WebSocket connect to "/cable" but got

    /Users/jshen/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.31.1-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:29:in `check_status': 14:
    failed to connect to all addresses. debug_error_string:{"created":"@1602860454.629484000","description":"
    Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":4090,"referenced_errors":
    [{"created":"@1602860453.508942000","description":"failed to connect to all 
    addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":394,"grpc_status":14}]} 
    (GRPC::Unavailable)

    when I added per README config.any_cable_rack.run_rpc = true I got

    /Users/jshen/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/gems/grpc-1.31.1-universal-darwin/src/ruby/lib/grpc/generic/client_stub.rb:47:
    in `initialize': grpc cannot be used before and after forking (RuntimeError)
    Vladimir Dementyev
    @palkan
    Interesting 🤔
    Have tried to run RPC server manually instead of run_rpc = true (i.e., bundle exec AnyCable)?
    Do you use Puma? Another option is set the number of workers to 1 (so, only one process)
    John Shen
    @johnshen64_gitlab
    Yes we use puma, setting workers to 1 still got the same grpc error, however, running anycable separately got rid of the grpc error but anycable is rejecting connection somehow but that is a separate issue from anycable-rack-server, which seems to be working now in sending websocket traffic to anycable. thanks!
    RPC Connect: <AnyCable::ConnectionRequest: env: <AnyCable::Env: url: "http://127.0.0.1:59684/cable/", headers: {"cookie"=>"CSRF-TOKEN=xxxxxx"}, cstate: {}, istate: {}>>
    Started "/cable/" [AnyCable] for  at 2020-10-16 10:06:29 -0700
    An unauthorized connection attempt was rejected
    Finished "/cable/" [AnyCable] for  at 2020-10-16 10:06:29 -0700 (Rejected)
    RPC Disconnect: <AnyCable::DisconnectRequest: identifiers: "{}", subscriptions: [], env: <AnyCable::Env: url: "http://127.0.0.1:59684/cable", headers: {"cookie"=>"CSRF-TOKEN=xxxxx"}, cstate: {}, istate: {}>>
    Finished "/cable" [AnyCable] for  at 2020-10-16 10:06:29 -0700 (Closed)
    Received pub/sub message: {"stream":"stage_questions:Z2lkOi8vYWRhaXIvU3RhZ2UvOTUw","data":"{\"stageQuestion\":{\"id\":1311,\"body\":\"Hopper\",\"votesEventRegistrationIds\":null,\"status\":\"asked\",\"votesCount\":1,\"eventRegistrationId\":2981,\"askerName\":null,\"askerInitials\":null,\"askerProfilePhotoUrl\":null},\"updateType\":\"NEW\"}"}
    Vladimir Dementyev
    @palkan
    John Shen
    @johnshen64_gitlab
    Will take a look. Thanks again!
    John Shen
    @johnshen64_gitlab

    Yes that got me further. However, now I wonder why this environmental variable causes anycable to hang indefinitely without any output.

    13:43 $ RAILS_ENV=test bundle exec anycable --debug
    (hangs forever)

    without it anycable runs fine

    13:48 $ bundle exec anycable
    Starting AnyCable gRPC server (pid: 69997, workers_num: 30)
    AnyCable version: 1.0.1 (proto_version: v1)
    gRPC version: 1.31.1
    Serving Rails application from ./config/environment.rb
    Broadcasting Redis channel: __anycable__
    RPC server is starting...
    RPC server is listening on 0.0.0.0:50051

    the reason I am trying with RAILS_ENV=test is because anycable seems to be not querying our test database with this error:

    PG::UndefinedTable: ERROR:  relation "users" does not exist
    LINE 8:  WHERE a.attrelid = '"users"'::regclass
    Vladimir Dementyev
    @palkan
    Check out your Rails logger settings for test env, AnyCable uses it when running in a Rails app.
    John Shen
    @johnshen64_gitlab
    Indeed adding logging to test made it work. Really appreciate your help!
    Serhii
    @SergeyNI

    Добрый день Владмир. Помогите пожалуйста. Обновил релиз anycable-rails (1.0.4). запускаю службу все ОК: Started command: bin/anycable-go --host=192.168.100.20 --debug --port=3334 --headers=cookies -ssl_cert=.ssh/server.crt -ssl_key=.ssh/server.key (pid: 219576)
    DEBUG 2020-10-25T05:04:51.083Z context=main 🔧 🔧 🔧 Debug mode is on 🔧 🔧 🔧
    INFO 2020-10-25T05:04:51.083Z context=main Starting AnyCable 1.0.2-ce5b4c5 (pid: 219576, open file limit: 1024)
    DEBUG 2020-10-25T05:04:51.083Z context=disconnector Calls rate: 10ms
    INFO 2020-10-25T05:04:51.083Z context=main Handle WebSocket connections at https://192.168.100.20:3334/cable
    INFO 2020-10-25T05:04:51.083Z context=main Handle health connections at https://192.168.100.20:3334/health
    INFO 2020-10-25T05:04:51.083Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, proto_versions: v0,v1)
    DEBUG 2020-10-25T05:04:51.083Z context=http Starting WebSocket server at https://192.168.100.20:3334
    INFO 2020-10-25T05:04:51.083Z context=pubsub Subscribed to Redis channel: anycable
    При установке соединения с фронтового приложения :
    RPC Connect: <AnyCable::ConnectionRequest: env: <AnyCable::Env: url: "https://192.168.100.20:3334/cable", headers: {"cookies"=>"", "REMOTE_ADDR"=>"192.168.100.20"}, cstate: {}, istate: {}>>
    Started "/cable" [AnyCable] for 192.168.100.20 at 2020-10-25 07:04:58 +0200
    Token is not found
    DEBUG 2020-10-25T05:04:58.089Z context=rpc Authenticate response: error_msg:"Token is not found"
    ERROR 2020-10-25T05:04:58.089Z context=ws Websocket session initialization failed: Application error: Token is not found

    Соединение через 'wss://192.168.100.20:3334/cable' пакет actioncable-vue
    Сертификат самоподписной
    В чем может быть проблема? Раньше работало. Какой ключ ему нужен?

    Vladimir Dementyev
    @palkan
    Привет! Это ошибка возвращается самим приложением, то есть в процессе вызова метода ApplicationCable#connectвыбрасывается исключение с текстом Token is not found.
    Как происходит аутентификация? Где хранится токен? Видимо, в куках (они пустые приходят, судя по логам).
    Serhii
    @SergeyNI
    для авторизации использую jwt_sessions. А там нажно в запрос запихнуть headers и cookies. Раньше куки передавались сами вроде.. наверно проблема в origins ?
    Serhii
    @SergeyNI
    есть ли где то пример авторизации через jwt_sessions? на фронте использую модуль actioncable-vue. то есть другой порт на моей машине а в продакшене планирую на разных docker контейнерах. подозреваю что проблема в ориджинсах что не передаются куки ..
    Vladimir Dementyev
    @palkan

    С браузера мы можем только в куках токен передать, а они у нас пустые.

    А не тут ли проблема: anycable-go --headers=cookies? Должно быть cookie

    Serhii
    @SergeyNI
    Проблема была в том, что не передавались куки, а они не передавались потому что путь предназначения куки не соответствовал путю запроса. У меня куки устанавливались через контроллер api/v1/signin он возвращал куки установленные jwt_sessions для пути "/api/v1/". А anycable поднимался по пути "/cable". Я установил путь api/v1/cable и cookies подтянулись все заработало. Спасибо за помощь.
    Jeremy Walker
    @iHiD

    Hi @palkan. We're shifting all our websockets to AnyCable at Exercism (https://exercism.io) as part of our version 3. I'm trying to be sure I understand the right way to deploy things, and hoping you could confirm I'm on the right tracks or correct me if I'm not!

    We are deploying to AWS. My current setup is to have a machine (running on Fargate, but that's probably irrelevant) with docker containers for anycable-go, the anycable gRPC server, and the rails app. I then have a separate Redis server. That machine is sitting behind a load balancer. So far it works great. The websockets set up fine and everything's talking to each other nicely.

    Where I'm unsure is if I add more of these machines behind the load balancer. Does having that separate Redis server give me the ability to have these machines sharing connection-knowledge. ie, if one machine broadcasts, but a different machine had been the one to establish the websocket, would the websocket still get broadcast. Or do these machines need to be able to communicate via gRPC directly? I'm feeling a little lost about how this bit works, so would appreciate your input.

    If you'd like to jump on a call or do this via email or GH issue instead, please let me know! Thanks for all your work on Anycable :)

    Vladimir Dementyev
    @palkan

    Hey Jeremy!

    Does having that separate Redis server give me the ability to have these machines sharing connection-knowledge

    Nope. RPC/WS servers do not communicate to each other, they rely on Redis to receive broadcasting events. Using separate Redis instances is only possible if you implement some kind of sharding: one Redis per application cluster (anycable-go and Rails apps).

    In case of AnyCable, Redis is not heavily utilized, its load doesn't depend on the number of connections, thus, a single instance is usually enough. And you can use Redis clusters with sentinels for the sake of availability.

    Vladimir Dementyev
    @palkan
    And, please, keep me posted) I'm very glad that Exercism is adopting AnyCable 🙂
    Jeremy Walker
    @iHiD
    @palkan Great. Thank you! :) Yes - I will keep you informed. Would you mind me dropping you an email if I have any more questions? :slight_smile:
    Vladimir Dementyev
    @palkan
    Sure)
    Jones Gladston
    @Jo_Gladsta_twitter
    Hi @palkan , So im integrating a chat feature for our Rails + vue app and im almost done with the development, thats when i came across anycable. We have around 1000 concurrent users in peak time, and im maintaining two subscription/socket per each tab/window open...would it be fine for now to just use Actioncable and switch to Anycable later??
    Vladimir Dementyev
    @palkan
    Hey Jones! Yeah, I think it should be fine for now. With AnyCable, you can save some resources (and money) but at this point it's probably not worth it
    Jones Gladston
    @Jo_Gladsta_twitter
    @palkan Cool! :D