From cdc744282c5dbe15403fd2bf1d8736d3e765cd1d 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prevent database disconnection in dbDisconnect() to avoid "Client must be connected" errors in production. The connection pool handles cleanup automatically. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- 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 32e4191..3eb4f97 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; };