Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Vladimir Dementyev
    @palkan

    @benydc

    ws://localhost:3000/cable url I try to connect to, which is rails backend

    that's an expected behavior since you're trying to connect to Rails Action Cable, no AnyCable;

    you should use ws://localhost:3334/cable

    and under Rails routes:

    and you don't need this mount in your routes.rb

    Vladimir Dementyev
    @palkan

    Is it possible to get connect/disconnect logs from anycable-go?

    Currently, there is no such option. We assume that AnyCable-go is running behind some proxy (such as NGINX), so it's not its responsibility.

    You can turn on access logs in the RPC app: https://docs.anycable.io/#/ruby/rails?id=access-logs

    Ben Chiciudean
    @benydc
    @palkan thanks!
    Joshua Sierles
    @jsierles
    @palkan Ah that's a shame. I suppose it would not be hard to add it, so I'll take a look
    RPC app access logs - will they contain the request headers like X-Request-ID?
    Alexey Krylov
    @forsaken1

    @palkan hello, Vladimir! could you help me?

    I wrote chats and it works fine on my local machine, but I cannot run anycable rpc server (bundle exec anycable) on staging server (configured on Hatchbox).
    Also I repeated the problem on my local machine with the same behavior like on the staging server, I run RAILS_ENV=staging SECRET_KEY_BASE=123 bundle exec anycable --rpc-host=127.0.0.1:50051 and nothing happens, process freezes without logs (I copied development configs to staging configs). The same for production env.

    cable.yml

    development:
      adapter: any_cable
    
    test:
      adapter: async
    
    staging:
      adapter: any_cable
    
    production:
      adapter: any_cable
      url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/5" } %>
      channel_prefix: rezilient-api_production
    Alexey Krylov
    @forsaken1
    before the task I made proof-of-concept of Rails-Anycable-React https://github.com/forsaken1/anycable-chat-example and here the same problem: don't works for production env (I set up adapter: any_cable)
    Miguel Michelson Martinez
    @michelson
    Hi @palkan , I have a design problem , not strictly related to the gem, but a design question. Have you seen the issue of when the same user is connected on 2 or more browser tabs ? how can I tell the backend that is one user ? it seems that action cable (or any cable) create 2 connections (it seems fine) but sends multiple messages not just one. The same happens on the typical Presence examples, when the same user is connected on multiple tabs I get wrong behaviors. any thoughts on this ? Thanks in advance!
    Vladimir Dementyev
    @palkan

    Hey @forsaken1!

    Have you tried to run bundle exec anycable with —debug flag or set Rails log level to debug?

    The example app doesn’t work in production locally? I’ll try to take a look tomorrow.

    @jsierles

    RPC app access logs - will they contain the request headers like X-Request-ID?

    Yes. You should see something like [AnyCable sid=<uuid>] ..., where uuid is extracted from the headers (if any). This feature has been added in the latest version.

    Vladimir Dementyev
    @palkan

    @michelson hey,
    For presence tracking I’d suggest relying on connection identifiers to determine the online status (how do you track the presence, by the way?). Even if you’ll be able to limit crosstab connections, users can still use different browsers/incognito modes/whatever (maybe, the chances are not so how but anyway).

    In theory, it’s possible to share one WebSocket connections between tabs but that would require rewriting the existing Action Cable client (haven’t heard about any existing attempts).

    Alexey Krylov
    @forsaken1
    @palkan hello, Vladimir, I solved problem, it was configuration problems plus I didn't seen logs aka "server started" when ran rpc server in staging/production env
    also I ran rpc server with other env than main application... and it's didn't worked for my proof-of-concept app
    Vladimir Dementyev
    @palkan

    I didn't seen logs aka "server started" when ran rpc server in staging/production env

    What is your Rails app log level and where does it print logs? AnyCable uses Rails logger under the hood, so you need to check its settings.

    Miguel Michelson Martinez
    @michelson
    Hi @palkan this is my presence implementation https://github.com/chaskiq/chaskiq/blob/master/app/channels/presence_channel.rb , it happens in this case that when the user is connected in two tabs (or browsers) and disconnect from one the server will trigger disconnection and I update the user state in database. but this is not reliable because it still one tab connected. I've tried to use the after_unsubscribe and count the redis connection for that key but does not work because the redis count is updated after the after_unsubscribe
    my other issue is that in the chat context I'm receiving messages twice when the same user is connected in two tabs. I've put a redis key in the middle to skip duplicated messages but it does not seem a good solution for this race condition
    Vladimir Dementyev
    @palkan

    For presence tracking I'd suggest relying on last_visited_at and recurrent pings at the channel level:

    def offline?
      last_visited_at > (PING_INTERVAL * 2).second.ago
    end

    That's the most robust way of tracking the presence; you shouldn't rely on disconnect/unsubscribe for critical features, 'cause it's hard to guarantee their invocation during server restarts or crashes.

    @michelson Could you point me to the code responsible for sending messages (both server and client side)?
    Miguel Michelson Martinez
    @michelson
    the offline? method that you suggest makes sense!
    Miguel Michelson Martinez
    @michelson
    in the messages logic I think that the error is on my side. the logic is :
    1. visitor receives message
    2. when message is rendered , there is a notification of "read" sent back through action cable.
    3. in the receive read method it could happen to another message will be dispatched automatically. <- and here is the issue.
    because when a user visiting the same chat in two tabs it register the read twice and auto messages could be dispatched twice.
    Miguel Michelson Martinez
    @michelson
    the channel message processor is here
    I've put a redis lock with a TTL in order to skip duplicated messages here but it not always works
    darlyn
    @bpdarlyn

    Hi, I am using the gem 'anycable-rails', '~> 0.5.0', but for any reason I can't access to the cookies, I am using the next

    #Procfile
    web: rails s
    rpc: ./bin/anycable --debug
    go: sleep 5 && ./cable/anycable-go-0.5.4-macos -disconnect_rate=1 -addr=$WEB_DOMAIN_SERVER:$WS_PORT -rpc=$RPC_HOST -log=true -headers=cookie,x-api-token,origin
    wepacker: ./bin/webpack-dev-server
    
    # setting the cookies
    cookies[:tenant] = 'subdomain'
    
    # connection.rb
    module ApplicationCable
      class Connection < ActionCable::Connection::Base
        identified_by :current_user
    
        def connect
          p cookies[:tenant]
          self.current_user = find_verified_user || reject_unauthorized_connection
        end
    
        protected
    
        def find_verified_user
          app_cookies_key = Rails.application.config.session_options[:key] ||
              raise("No session cookies key in config")
          env["rack.session"] = cookies.encrypted[app_cookies_key]
          Warden::SessionSerializer.new(env).fetch(:user)
        end
      end
    end

    But the roc log on p cookies[:tenant] is nil, also is find_verified_user is nil, do you have some idea, what's wrong?

    I am using the devise gem version 4.3.0
    my environment vars, these are:
    WEB_DOMAIN_SERVER=lvh.me
    RPC_HOST=${WEB_DOMAIN_SERVER}:50051
    WS_PORT=3334
    WS_URL=ws://${WEB_DOMAIN_SERVER}:${WS_PORT}/cable
    darlyn
    @bpdarlyn
    image.png
    image.png
    Miguel Michelson Martinez
    @michelson
    hey @bpdarlyn have you seen this ? anycable/anycable-rails#24
    could be a CORS problem ?
    are you using different domains ?
    darlyn
    @bpdarlyn
    Yes I saw it, CORS I don't thing so, I think is possible with the subdomains is falling something?
    My Host is: http://libertad.lvh.me:5000
    ws-server: lvh.me:3334
    rpc-server: lvl.me:50051
    ws-url: ws://lvh.me:3334/cable
    the uniq problem is with cookies, in a controller I am set some cookie like for example cookies[:tenant]='libertad' if a print on chrome developer tool document.cookie this print libertad
    Miguel Michelson Martinez
    @michelson
    I'm not maintainer, but you could send the cookie as a header and catch it in the application cable ?
    as a workaround
    darlyn
    @bpdarlyn
    sorry, I am newbie in this, how do you do that ?
    Miguel Michelson Martinez
    @michelson
    if you fallback to vanilla actioncable, works ?
    darlyn
    @bpdarlyn

    ok I found the problem, when I mount the cable url:
    rpc-host: 0.0.0.0:50051
    ws-host: 0.0.0.0:3334
    this above setting is perfect, no problem, the problem is here when I send this:

    # wrong empty cookies
    ws-url: lvh.me:3334/cable
    
    # good, I have all cookies
    ws-url: libertad.lvh.me:3334/cable
    
    # because my host is
    host: libertad.lvh.me:5000

    My app is multitenant I how I will change, the ws-url by subdomain ?

    Miguel Michelson Martinez
    @michelson
    yup , it's a cors error then
    Vladimir Dementyev
    @palkan

    @bpdarlyn

    My app is multitenant I how I will change, the ws-url by subdomain ?

    You can share cookies between subdomains using :all option; see https://docs.anycable.io/#/troubleshooting?id=my-websocket-connection-fails-with-quotauth-failedquot-error

    That's a common practice for multi tenant apps with subdomains.

    bilal-tx
    @bilal-tx
    Hello everyone!
    i am facing difficulty with heroku.
    D, [2020-03-03T10:39:09.729670 #7] DEBUG -- : [AnyCable sid=f9aedddc-db06-4faa-ab35-a67fbf734fcf] RPC Disconnect: <AnyCable::DisconnectRequest: identifiers: "{\"__ltags__\":[\"ActionCable\",null]}", subscriptions: ["{\"channel\":\"NotificationChannel\"}", "{\"channel\":\"ReportChannel\"}", "{\"channel\":\"ChatChannel\"}", "{\"channel\":\"CardsChannel\"}", "{\"channel\":\"CbkChannel\"}", "{\"channel\":\"CheckoutChannel\"}", "{\"channel\":\"CustomerNotificationChannel\"}"], path: "/cable", headers: {"REMOTE_ADDR"=>"10.171.230.57", "cookie"=>""}>
    please help me
    Vladimir Dementyev
    @palkan

    Hey @bilal-tx!

    What is the exact problem? This log line shows the Disconnect command which is called when a WS connection is closed

    AppsGenii
    @appsgenii
    Hey, How can I install anycable on production server - Ubuntu 18.04 is there any step by step guidelines avaialble.
    Vladimir Dementyev
    @palkan
    Hey! I guess, you're asking about anycable-go server. In that case, the easiest way is to download a precompiled binary from GitHub releases: https://github.com/anycable/anycable-go/releases
    Konrad KM
    @Bunagana
    Hey @palkan, what would be the best way to go about adding the ability to get the params in the ws-url locahost:3334/cable(/:channel_id/:username) in the case cookies cannot be used. Thanks
    Vladimir Dementyev
    @palkan
    Hey! You can use query params: /cable?channel_id=x&username=y. And then you can access them via request.params in the connection class
    getauvi
    @getauvi_twitter
    Hello,
    I am using AnyCable in Heroku (anycable-go, redis). But when I want to do a broadcast I get a Redis error:
    Redis::CommandError (ERR max number of clients reached)
    I know the Redis plan allows 30 connections. Is there a way not to use many Redis connections?
    Thanks
    Vladimir Dementyev
    @palkan

    Hey!
    AnyCable uses a single connection to Redis for broadcast and another one for receiving messages at the AnyCable-Go side.

    What else do you use Redis for? And how many dynos do you have?

    getauvi
    @getauvi_twitter
    We use the redis instance as a KV store for rails fragments caching, and access redis from rails in a request/response cycle. Nothing fancy. We have 2 dynos (1 for the app running a single passenger instance and 1 for the rpc/anycable-go combo).
    getauvi
    @getauvi_twitter

    We use the redis instance as a KV store for rails fragments caching, and access redis from rails in a request/response cycle. Nothing fancy. We have 2 dynos (1 for the app running a single passenger instance and 1 for the rpc/anycable-go combo).

    Update: I didn't realize that some of the test machines were connecting to the redis server. Problem solved. Anycable works like a charm, many thanks for creating it!

    Vladimir Dementyev
    @palkan
    👍 🙂