How to Fix MongoDB Error 384 (ConnectionError)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mongodb error 384 when a network link drops inside the database cluster. You fix it by checking network routes, fixing firewall rules, and retrying the failed request. MongoDB names this issue ConnectionError. It falls under the NetworkError, RetriableError, and InternalOnly groups. This means the database engine uses this code for its own internal network checks. Because it is a retriable error, a fresh attempt often works right away. Still, repeated errors mean your team must inspect

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 384 when a network link drops inside the database cluster. You fix it by checking network routes, fixing firewall rules, and retrying the failed request.

MongoDB names this issue ConnectionError. It falls under the NetworkError, RetriableError, and InternalOnly groups. This means the database engine uses this code for its own internal network checks. Because it is a retriable error, a fresh attempt often works right away. Still, repeated errors mean your team must inspect the network path between nodes.

What causes mongodb error 384 in your cluster

A database cluster relies on constant talk between its servers. When one node cannot reach another node, the system logs code 384. This happens during elections, data syncs, or shard routing.

The InternalOnly tag tells you that client apps rarely cause this code by themselves. Instead, a shard router or primary node hits a dead link to a peer. Then, the server flags the broken link as a ConnectionError.

Common triggers include strict firewall rules, bad DNS records, or full network sockets. A sudden spike in traffic can also exhaust open ports on a host. When ports run out, new internal links fail right away. Cloud network blips or host reboots also break active links between database nodes. If a node restarts during a read or write, peers log this network failure.

How to diagnose and fix the failure safely

Start by checking your server logs for the exact time the error began. Look for the IP address or host name of the peer that failed to respond. This tells you which network segment has trouble.

Next, test the network path between the affected database servers. Check that your security groups allow traffic on the ports your nodes use. Verify that DNS names resolve to the right internal IP addresses. If a host has high CPU or memory load, it may drop network packets. Balancing the load across your cluster helps stop these timeouts.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Because code 384 is a RetriableError, your app driver can often recover on its own. Make sure your client app uses current driver settings that retry failed reads and writes. When the cluster finishes a failover, the retry will hit a healthy node.

Keeping access safe while you fix production

When engineers inspect a broken cluster, do not hand out full admin keys. MongoDB grants access through role-based rules that apply to a specific database. A role can grant access down to a single collection.

Give your team the built-in read role when they only need to check data. This role allows actions like find, listCollections, listIndexes, dbStats, and collStats on non-system collections. It blocks actions that change data, such as insert, update, remove, or dropCollection. If an engineer must change data or build an index, assign the readWrite role instead. Notice that self-hosted deployments and cloud clusters use different built-in roles, though both use the same privilege actions.

You should also protect sensitive fields during debugging sessions. Data masking rewrites matched fields like emails, phone numbers, card numbers, or national IDs in query results. This lets engineers check database state and fix network errors while keeping private records safe.

Add command guardrails and field masking beside MongoDB

Collection roles and IP rules control who connects to MongoDB. Yet an active client or agent session can still run a pipeline that writes data or reads raw personal fields. In practice, hoop.dev sits inline in the wire protocol beside your database as a sidecar for your MongoDB. For every command an agent or human sends in production, hoop.dev decides to pass, mask, block, or escalate it for review.

Using hoop.dev MongoDB controls, guardrails refuse banned commands before they run or hold risky calls for approval, and data masking rewrites matched fields in returned documents in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for GDPR, HIPAA, and PCI DSS programs. View the project on GitHub.

Frequently asked questions

Is MongoDB error 384 safe to retry in my app?

Yes, MongoDB marks code 384 as a RetriableError in its official error list. Once the network link recovers or a failover finishes, a retry will go through.

Why is ConnectionError marked as InternalOnly?

The InternalOnly category means the database engine uses this code for internal node talk. You will mostly see it in server logs when nodes lose contact with each other.

What database role should engineers use to check cluster stats?

Assign the built-in read role on the target database. It lets engineers run dbStats and collStats without letting them insert, update, or remove records.

The query runs. The emails stay hidden.