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

Allow users to configure an external datastore for WebSocket connections so that session or connection information isn’t limited to a single pod’s memory #1872

Open
kaykumar opened this issue Feb 6, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@kaykumar
Copy link

kaykumar commented Feb 6, 2025

Currently, our application relies on sticky sessions to maintain websocket connections in a horizontally scaled environment. However, sticky sessions can sometimes fail to route clients to the correct pod, causing dropped or mismatched sessions. This creates potential downtime or data inconsistency when multiple pods are running.

To address this, we want the ability to configure a distributed state manager—such as Redis—so that websocket states are synchronized across all pods. This will ensure that any pod can handle websocket events without relying solely on sticky session routing.

Proposed Change

In server.py (around line 96), instead of creating the Socket.IO server without a shared state manager:

//Read the Redis URL from an environment variable (or some config).
// Example: "redis://redis-service:6379/0"
redis_url = os.getenv("REDIS_URL")

// Conditionally enable the Redis manager if configured.
if redis_url:
mgr = socketio.RedisManager(redis_url)
sio = socketio.Server(
async_mode='asgi', # or 'gevent', 'threading', etc.
client_manager=mgr
)
else:
// Fallback to default behavior with no external manager
sio = socketio.Server(
async_mode='asgi'
)

@dosubot dosubot bot added the enhancement New feature or request label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant