Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[request] Custom Redis client settings using environment variables #225

Open
stayallive opened this issue Dec 30, 2021 · 13 comments · Fixed by #228
Open

[request] Custom Redis client settings using environment variables #225

stayallive opened this issue Dec 30, 2021 · 13 comments · Fixed by #228
Assignees
Labels
goal:enhancement New feature or request

Comments

@stayallive
Copy link
Collaborator

We are using a managed database by Digital Ocean and they require an SSL connection. AWS ElastiCache and many other managed solutions have the same requirement.

This is "easy" to enable by adding a tls: {} to the options passed to new Redis({...}). However I have a hard time figuring out how to do this nicely so we can have a DB_REDIS_TLS=true and it doing tls: {} or tls: undefined (which is the default) based on that value. Any help would be appreciated :)

I also noticed that when Redis has a connection problem it spins out of control (consuming ~1 core of CPU time) in an infinite loop barfing this when in debug mode:

Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:164:15)
    at writeGeneric (node:internal/stream_base_commons:155:3)
    at Socket._writeGeneric (node:net:795:11)
    at Socket._write (node:net:807:8)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at Redis.sendCommand (/usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/index.js:672:33)
    at /usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/event_handler.js:256:26
    at Socket.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/event_handler.js:46:39) {
  errno: -32,
  code: 'EPIPE',
  syscall: 'write'
}
Error: write ECONNRESET
    at afterWriteDispatched (node:internal/stream_base_commons:164:15)
    at writeGeneric (node:internal/stream_base_commons:155:3)
    at Socket._writeGeneric (node:net:795:11)
    at Socket._write (node:net:807:8)
    at writeOrBuffer (node:internal/streams/writable:389:12)
    at _write (node:internal/streams/writable:330:10)
    at Socket.Writable.write (node:internal/streams/writable:334:10)
    at Redis.sendCommand (/usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/index.js:672:33)
    at /usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/event_handler.js:256:26
    at Socket.<anonymous> (/usr/lib/node_modules/@soketi/soketi/node_modules/ioredis/built/redis/event_handler.js:46:39) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'write'
}

Maybe we should have a little more conservatie retry strategy.

@rennokki
Copy link
Member

I think I'll start implementing support for JSON-based configurations as files. This way it's better to configure nested values 🤔 (https://github.com/soketi/soketi/projects/1#card-64718909)

@rennokki
Copy link
Member

I think that environment variables wouldn't be a great choice for complex configurations. I don't really know why I started doing that in the first place, but having a JSON file that can be configured would be easier.

{
    "database.redis.tls": { ... }
}
soketi start --config=/path/to/config.json

@stayallive
Copy link
Collaborator Author

Honestly having it makes setting up a server really quick and easy... so I like having the JSON option but would not call the env variables bad honestly.

Also for the TLS option, it just needs to be an empty object so there is not much to configure unless you also want to implement reading files from disk.

@rennokki
Copy link
Member

Still going to work on this to make env variables for this a thing 🤔

@ajnozari
Copy link

Any update on allowing env variables for this?

@mackensiealvarezz
Copy link

Is there any way of doing this with environment variables ?

@stayallive
Copy link
Collaborator Author

stayallive commented Mar 13, 2022

No it is not, but it's very easy to do with the JSON (in addition to your environment variables).

Create a file called config.json on your server which should be accessible by the user running Soketi with the following contents:

{
    "database.redis.tls": {}
}

Instead of running just soketi start, change it to soketi start --config=/home/soketi/config.json (change the path to the config.json to where you placed it) and then you can use a Redis host using TLS (like a Digital Ocean managed Redis instance).

@rennokki
Copy link
Member

I had to postpone this issue. For now, the config should work perfectly fine.

@rennokki rennokki added the goal:enhancement New feature or request label Mar 17, 2022
@rennokki rennokki changed the title Allow TLS for Redis connection Custom Redis client settings using environment variables Mar 17, 2022
@mackensiealvarezz
Copy link

I'm using the docker image inside of my helm chart. How can I pass this command? It looks like the command automatically runs when the container starts.

I tried this but it didn't work

        - name: soketi
          image: quay.io/soketi/soketi:0.32.2-16-alpine
          command:
            - node
            - /app/bin/server.js
            - start --config=/etc/configws/config.json

@rennokki
Copy link
Member

Have you injected the file in the pod?

@mackensiealvarezz
Copy link

mackensiealvarezz commented Apr 15, 2022

Yes, I created a custom configmap with:

{
    "database.redis.tls": {}
}

and mounted it to /etc/configws/config.json

I also exec into the pod and confirmed the file was there. I tried to also exec into the pod and run node server.js start --config=/etc/configws/config.json. When i did that, the pod just terminates and crashes

@rennokki rennokki changed the title Custom Redis client settings using environment variables [request] Custom Redis client settings using environment variables Aug 17, 2022
@winfamy
Copy link

winfamy commented Jan 30, 2023

@mackensiealvarezz I FIGURED YOUR ISSUE OUT
I've been going through this myself trying to figure out how to do this (TLS on Redis)

        - name: soketi
          image: quay.io/soketi/soketi:0.32.2-16-alpine
          command:
            - node
            - /app/bin/server.js
            - start --config=/etc/configws/config.json

is an incorrect way of specifying the command block for a docker-compose config. Instead, you need to separate your last line!!!!!

        - name: soketi
          image: quay.io/soketi/soketi:0.32.2-16-alpine
          command:
            - node
            - /app/bin/server.js
            - start 
            - --config=/etc/configws/config.json

This worked for me! Quite literally one of the worst experiences troubleshooting Docker I have ever had.

(sorry unrelated to issue at hand, but will prevent someone from troubleshooting Docker + Soketi for a few hours)

@rennokki rennokki self-assigned this Aug 3, 2023
@limadelrey
Copy link

Is there any update on allowing to configure TLS using an environment variable? ☝️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goal:enhancement New feature or request
Development

Successfully merging a pull request may close this issue.

6 participants