Skip to content

Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active

chore: clear timeouts

Danny Avila7afe09fa0209
diff --git a/api/lib/db/indexSync.js b/api/lib/db/indexSync.js
index 9902ad6bcf..e42f5319e6 100644
--- a/api/lib/db/indexSync.js
+++ b/api/lib/db/indexSync.js
@@ -2,6 +2,7 @@ const mongoose = require('mongoose');
const Conversation = mongoose.models.Conversation;
const Message = mongoose.models.Message;
const { MeiliSearch } = require('meilisearch');
+let currentTimeout = null;
// eslint-disable-next-line no-unused-vars
async function indexSync(req, res, next) {
@@ -46,7 +47,7 @@ async function indexSync(req, res, next) {
// console.log('in index sync');
if (err.message.includes('not found')) {
console.log('Creating indices...');
- setTimeout(async () => {
+ currentTimeout = setTimeout(async () => {
try {
await Message.syncWithMeili();
await Conversation.syncWithMeili();
@@ -61,4 +62,9 @@ async function indexSync(req, res, next) {
}
}
+process.on('exit', () => {
+ console.log('Clearing sync timeouts before exiting...');
+ clearTimeout(currentTimeout);
+});
+
module.exports = indexSync;