mirror of
https://github.com/open-webui/open-webui.git
synced 2026-06-14 03:30:25 +00:00
fix: clear usage interval in finally so it cannot leak on send failure (#25478)
getChatEventEmitter starts a setInterval emitting a `usage` socket event every second; clearInterval ran only after sendMessageSocket resolved, so any throw/reject left the interval firing for the page lifetime. Each failed send added another orphaned interval, inflating server-side usage accounting and growing CPU/memory over a session. Wrap the send in try/finally so the interval is always cleared, on both the happy path and any thrown/rejected path. The exception still propagates unchanged. Fixes #25465 Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2159,22 +2159,24 @@
|
||||
if (primaryModel && primaryResponseMessageId) {
|
||||
const chatEventEmitter = await getChatEventEmitter(primaryModel.id, _chatId);
|
||||
|
||||
scrollToBottom();
|
||||
await sendMessageSocket(
|
||||
primaryModel,
|
||||
messages && messages.length > 0
|
||||
? messages
|
||||
: createMessagesList(_history, primaryResponseMessageId),
|
||||
_history,
|
||||
primaryResponseMessageId,
|
||||
_chatId,
|
||||
{
|
||||
messageIdsMap: selectedModelIds.length > 1 ? messageIdsMap : undefined,
|
||||
regenerationPrompt
|
||||
}
|
||||
);
|
||||
|
||||
if (chatEventEmitter) clearInterval(chatEventEmitter);
|
||||
try {
|
||||
scrollToBottom();
|
||||
await sendMessageSocket(
|
||||
primaryModel,
|
||||
messages && messages.length > 0
|
||||
? messages
|
||||
: createMessagesList(_history, primaryResponseMessageId),
|
||||
_history,
|
||||
primaryResponseMessageId,
|
||||
_chatId,
|
||||
{
|
||||
messageIdsMap: selectedModelIds.length > 1 ? messageIdsMap : undefined,
|
||||
regenerationPrompt
|
||||
}
|
||||
);
|
||||
} finally {
|
||||
if (chatEventEmitter) clearInterval(chatEventEmitter);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user