mirror of
https://github.com/open-webui/open-webui.git
synced 2026-05-05 18:38:17 -05:00
[PR #7780] [CLOSED] Disable Polling Transport When WebSockets Are Enabled and Implement Cleanup Locking Mechanism #22106
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/7780
Author: @jk-f5
Created: 12/11/2024
Status: ❌ Closed
Base:
dev← Head:disablepolling📝 Commits (1)
5a3b650feat: Make ENABLE_WEBSOCKET_SUPPORT disable polling entirely to allow multiple replicas without sticky sessions.📊 Changes
4 files changed (+83 additions, -33 deletions)
View changed files
📝
backend/open_webui/apps/socket/main.py(+52 -31)📝
backend/open_webui/apps/socket/utils.py(+24 -0)📝
backend/open_webui/main.py(+2 -0)📝
src/routes/+layout.svelte(+5 -2)📄 Description
Overview
This merge request introduces changes to optimize WebSocket usage and ensure proper operation in distributed environments.
periodic_usage_pool_cleanuptask across multiple instances in a distributed deployment.Changes
1. Disable Polling Transport When WebSockets Are Enabled
Rationale:
By default, Socket.IO uses both
pollingandwebsockettransports. In environments with multiple application instances (replicas) behind a load balancer without sticky sessions, thepollingtransport can lead to connectivity issues:400 Errors Without Sticky Sessions:
pollingtransport relies on HTTP long-polling requests that must consistently reach the same server instance. Without sticky sessions, requests from the same client may be routed to different instances, causing the server to not recognize the session and respond with HTTP 400 errors.Solution:
pollingtransport and using onlywebsocket, which operates over a persistent TCP connection, we avoid the need for sticky sessions.Benefits:
2. Implement Redis-Based Locking for
periodic_usage_pool_cleanupRationale:
In a distributed deployment with multiple instances of the application, running the
periodic_usage_pool_cleanuptask concurrently can lead to race conditions and inconsistent state in theUSAGE_POOL. By introducing a Redis-based lock:Ensures Single Instance Execution:
Compatibility with Distributed Systems:
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.