How to Fix MongoDB Error 145 (PooledConnectionsDropped)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 145 when the database drops active sockets from a pool. You fix this PooledConnectionsDropped fault by stabilizing network paths and tuning pool limits. Database nodes keep open links ready in a shared pool to save time. When a network glitch or node restart happens, those idle links break at once. The server then returns code 145 to warn that pooled links were dropped. Teams must find the root cause of the drop before queries start failing. What causes mongodb error 145

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You see mongodb error 145 when the database drops active sockets from a pool. You fix this PooledConnectionsDropped fault by stabilizing network paths and tuning pool limits.

Database nodes keep open links ready in a shared pool to save time. When a network glitch or node restart happens, those idle links break at once. The server then returns code 145 to warn that pooled links were dropped. Teams must find the root cause of the drop before queries start failing.

What causes mongodb error 145 in a cluster

The official name for mongodb error 145 is PooledConnectionsDropped. It happens when a router or node clears out open network sockets. A common trigger is a replica set stepdown or a primary node change. When a primary node steps down, it closes open links to stop stale writes.

Network appliances between your app and the database also cause this error. Firewalls and load balancers often drop idle sockets without telling the database node. When the node tries to use that dead socket, the pool drops it. High memory stress or hitting socket limits on the host also triggers drops.

Client apps and query routers both maintain pools of open links to nodes. If an app opens too many links during a traffic spike, nodes struggle. The operating system might reset sockets when file descriptors run out. Each dropped link logs an event and slows down the next batch of queries.

Start by checking the database server logs around the time of the error. Look for replica set election messages or host memory warnings at that exact second. Check your firewall idle timeout rules and make sure app keepalive timers run faster. This stops middleboxes from killing quiet links behind the scenes.

When engineers log in to check cluster stats, keep role permissions tight. MongoDB grants access through roles that define allowed actions on specific resources. A role applies to its defined database and works down to the collection level. Do not hand out full admin rights just to inspect pool health.

MongoDB Authentication & Authorization + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Instead, assign a read role when checking stats on a specific database. The built-in read role grants actions like dbStats, collStats, find, listCollections, and listIndexes. It blocks write actions such as insert, update, remove, or dropCollection during live checks. Note that Atlas users and self-hosted users have different built-in role sets.

After you confirm the cause in the logs, adjust your client pool sizing. Lower the max pool size if apps open more links than nodes can hold. Set a clean max idle time in the client so apps close old links first. This lets the app retire idle sockets before a firewall cuts them off.

How to stop pool drops from coming back

Keep your driver versions current so retry logic works as designed during node elections. Modern drivers catch code 145 and open a fresh link for read operations. Still, writes that were in flight during a drop may still return errors. Build app logic to retry safe writes when a pool refresh occurs.

Monitor open socket counts across all app instances and ad-hoc user sessions. Sometimes a spike in engineer queries pushes a node past its connection cap. Limit direct node sessions and route human queries through a central point. Also use data masking to rewrite matched fields like emails or phone numbers in results. This protects sensitive records while engineers inspect live query failures.

Check MongoDB commands and documents on the wire

MongoDB roles and SCRAM login decide who opens a session. They do not check single commands or redact sensitive fields inside returned documents. With hoop.dev, you run an open-source proxy, a sidecar for your MongoDB, inline in the MongoDB wire protocol. On every command an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.

Before a command runs, hoop.dev guardrails check its effect and refuse banned drops or writes with MongoDB error code 13, or hold risky commands for approval. On the way back, hoop.dev data masking rewrites sensitive fields in returned documents in memory, and every verdict is logged. See the open-source code on GitHub.

Frequently asked questions

What does PooledConnectionsDropped mean in MongoDB?

PooledConnectionsDropped is the official name for error code 145 in MongoDB. It means the server or router closed open links in its connection pool.

Does error 145 mean my database crashed?

Not always, because a simple network timeout or primary stepdown triggers this code. Check your server logs to see if a node restarted or just stepped down.

Which role should engineers use to inspect database stats?

Give engineers a role with only the read actions needed, like dbStats and collStats. The built-in read role allows these checks while blocking insert, update, and remove actions.

The query runs. The emails stay hidden.