-
-
Notifications
You must be signed in to change notification settings - Fork 24.1k
Bugfix/Redis Pub Sub Streaming #5884
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,10 +42,19 @@ const createAndStreamInternalPrediction = async (req: Request, res: Response, ne | |||||||||||||
| res.setHeader('X-Accel-Buffering', 'no') //nginx config: https://serverfault.com/a/801629 | ||||||||||||||
| res.flushHeaders() | ||||||||||||||
|
|
||||||||||||||
| if (process.env.MODE === MODE.QUEUE) { | ||||||||||||||
| const isQueueMode = process.env.MODE === MODE.QUEUE | ||||||||||||||
| if (isQueueMode) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.subscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Detect client disconnect (browser close, network timeout, ALB idle timeout) | ||||||||||||||
| res.on('close', () => { | ||||||||||||||
| sseStreamer.removeClient(chatId) | ||||||||||||||
| if (isQueueMode) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.unsubscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| const apiResponse = await utilBuildChatflow(req, true) | ||||||||||||||
| sseStreamer.streamMetadataEvent(apiResponse.chatId, apiResponse) | ||||||||||||||
| } catch (error) { | ||||||||||||||
|
|
@@ -55,6 +64,9 @@ const createAndStreamInternalPrediction = async (req: Request, res: Response, ne | |||||||||||||
| next(error) | ||||||||||||||
| } finally { | ||||||||||||||
| sseStreamer.removeClient(chatId) | ||||||||||||||
| if (process.env.MODE === MODE.QUEUE) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.unsubscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+67
to
+69
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, you can use the
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| export default { | ||||||||||||||
|
|
||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -72,10 +72,19 @@ const createPrediction = async (req: Request, res: Response, next: NextFunction) | |||||||||||||
| res.setHeader('X-Accel-Buffering', 'no') //nginx config: https://serverfault.com/a/801629 | ||||||||||||||
| res.flushHeaders() | ||||||||||||||
|
|
||||||||||||||
| if (process.env.MODE === MODE.QUEUE) { | ||||||||||||||
| const isQueueMode = process.env.MODE === MODE.QUEUE | ||||||||||||||
| if (isQueueMode) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.subscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| // Detect client disconnect (browser close, network timeout, ALB idle timeout) | ||||||||||||||
| res.on('close', () => { | ||||||||||||||
| sseStreamer.removeClient(chatId) | ||||||||||||||
| if (isQueueMode) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.unsubscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| const apiResponse = await predictionsServices.buildChatflow(req) | ||||||||||||||
| sseStreamer.streamMetadataEvent(apiResponse.chatId, apiResponse) | ||||||||||||||
|
Comment on lines
88
to
89
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||||||||||||||
| } catch (error) { | ||||||||||||||
|
|
@@ -85,6 +94,9 @@ const createPrediction = async (req: Request, res: Response, next: NextFunction) | |||||||||||||
| next(error) | ||||||||||||||
| } finally { | ||||||||||||||
| sseStreamer.removeClient(chatId) | ||||||||||||||
| if (process.env.MODE === MODE.QUEUE) { | ||||||||||||||
| getRunningExpressApp().redisSubscriber.unsubscribe(chatId) | ||||||||||||||
| } | ||||||||||||||
|
Comment on lines
+97
to
+99
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, you can use the
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| } else { | ||||||||||||||
| const apiResponse = await predictionsServices.buildChatflow(req) | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the external predictions controller, the
chatIdhere is user-controlled and used to route SSE events. An attacker with access to the internal API can hijack another user's chat stream within the same workspace by providing a collidingchatId. This allows the attacker to receive real-time chat events intended for another user. Ensure thatchatIdis generated server-side or validated for uniqueness and ownership before being used to establish an SSE connection.