anycable / anycable-go

AnyCable real-time server
https://anycable.io
MIT License
377 stars 65 forks source link

Anycable-go ignores Redis database number #188

Closed haukot closed 1 year ago

haukot commented 1 year ago

AnyCable-Go version: 1.4.3-214a549

AnyCable gem version: anycable (1.4.1)

What did you do?

We are using Anycable with a single-instance Redis, and it appears that Anycable-go ignores the Redis database number.

For clarity in the experiment, I ran only anycable-go with the following configuration:

    command: anycable-go --redis_url redis://redis:6379/3
    environment:
      REDIS_URL: redis://redis:6379/1
      ANYCABLE_REDIS_URL: redis://redis:6379/2

Based on the output of --help, it seems that the Redis URL is detected correctly(as it changes default to "redis://redis:6379/2"):

root@463e913b0612:/app# anycable-go --help | grep redis_url
   --redis_url value                          Redis url (default: "redis://redis:6379/2") [$ANYCABLE_REDIS_URL, $REDIS_URL]

I've looked onto code, and it seems it does not send SelectDB to rueidis, nor uses ParseURL, and InitAddress contains only host, so it always connects to default database 0.

What did you expect to happen?

Anycable-go uses database 2.

What actually happened?

On the clear Redis instance it sets keys only for database 0.

/data # redis-cli -n 0
127.0.0.1:6379> KEYS *
1) "__anycable__"
127.0.0.1:6379> select 1
OK
127.0.0.1:6379[1]> KEYS *
(empty array)
127.0.0.1:6379[1]> select 2
OK
127.0.0.1:6379[2]> KEYS *
(empty array)
127.0.0.1:6379[2]> select 3
OK
127.0.0.1:6379[3]> KEYS *
(empty array)
127.0.0.1:6379[3]> select 4
OK
127.0.0.1:6379[4]> KEYS *
(empty array)
127.0.0.1:6379[4]> select 5
OK
127.0.0.1:6379[5]> KEYS *
(empty array)
127.0.0.1:6379[5]>
/data #

On the other side, gem anycable does change the database number depending on the url, and will create a key in a not default database.

Anycable-go logs:

DEBUG 2023-09-07T05:38:12.974Z context=main 🔧 🔧 🔧 Debug mode is on 🔧 🔧 🔧                                                                   [5/6804]
 INFO 2023-09-07T05:38:12.974Z context=main Starting AnyCable 1.4.3-214a549 (pid: 1, open file limit: 1048576, gomaxprocs: 8)                            
 INFO 2023-09-07T05:38:12.974Z context=main Anonymized telemetry is on. Learn more: https://docs.anycable.io/anycable-go/telemetry                       
 INFO 2023-09-07T05:38:12.974Z context=main Using in-memory broker (epoch: yR3N, history limit: 5000, history ttl: 20s, sessions ttl: 300s)              
DEBUG 2023-09-07T05:38:12.974Z context=disconnector Calls rate: 10ms                                                                                     
 WARN 2023-09-07T05:38:12.974Z context=main Using a non-distributed broadcaster without a pub/sub enabled; each broadcasted message is only processed by a single node
 INFO 2023-09-07T05:38:12.974Z consumer=Zir5Yw context=broadcast id=Zir5Yw provider=redisx stream=__anycable__ Starting Redis broadcaster at redis:6379
 INFO 2023-09-07T05:38:12.975Z context=rpc RPC controller initialized: localhost:50051 (concurrency: 28, impl: grpc, enable_tls: false, proto_versions: v

 INFO 2023-09-07T05:38:12.975Z context=main Handle WebSocket connections at http://0.0.0.0:8080/cable
 INFO 2023-09-07T05:38:12.975Z context=main Handle health requests at http://0.0.0.0:8080/health
DEBUG 2023-09-07T05:38:12.975Z context=main Go pools initialized (remote commands: 256)
DEBUG 2023-09-07T05:38:12.975Z context=http Starting WebSocket server at http://0.0.0.0:8080
DEBUG 2023-09-07T05:38:12.975Z context=metrics No metrics writers. Disable metrics rotation
palkan commented 1 year ago

Thanks for the report!

nor uses ParseURL

Oh, nice, didn't know they finally added it.

Will fix soon and include in the next release.