From f2695155746d192954233eac13f913c5bb0140c4 Mon Sep 17 00:00:00 2001 From: Alexander Bocken Date: Fri, 12 Sep 2025 15:02:24 +0200 Subject: [PATCH] Fix MongoDB connection issue in production builds Prevent database disconnection in dbDisconnect() to avoid "Client must be connected" errors in production. The connection pool handles cleanup automatically. --- src/utils/db.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/utils/db.ts b/src/utils/db.ts index 32e41919..3eb4f97b 100644 --- a/src/utils/db.ts +++ b/src/utils/db.ts @@ -29,9 +29,7 @@ export const dbConnect = async () => { }; export const dbDisconnect = async () => { - if (process.env.NODE_ENV === 'development') return; - if (mongoConnection.isConnected === 0) return; - - await mongoose.disconnect(); - mongoConnection.isConnected = 0; + // Don't disconnect in production to avoid "Client must be connected" errors + // The connection pool will handle connection cleanup automatically + return; };