Writing to DB stops after some time (MongoServerSelectionError: connect ENOBUFS

Hello, I have a strange error, and can’t find similar solutions to fix it. I would be incredibly grateful if someone could help me with it.
My environment: windows 11, mongodb community server (v5.0.10), nodejs 16.3.0 version.

I wrote a script that makes requests through a proxy to a specific endpoint in a for loop, receives the data, and writes it to a collection. At first, I used the updateOne() method, then I switched to the bulkWrite() method, although I’m not sure if it can help in any way. The problem is that I make 25 requests per minute (and this number will grow in the future), and after 4000 or 5000 requests, my code throws the following error:

const timeoutError = new MongoServerSelectionError(
MongoServerSelectionError: connect ENOBUFS - Local (undefined:undefined)

I want the code to work for at least 24 hours without errors.
After research I guess that the problem was that mongod was not running, but I started it through cmd and I’m not sure that that’s a reason.

I can provide code examples/logs/any additional info. Thanks for any help.

Hey @Mykhailo_Popovych,

Welcome to the MongoDB Community Forums! :leaves:

The ENOBUFS error usually indicates that the system’s network buffer is full, and it cannot establish a new connection. You mentioned that you make 25 requests per minute, which translates to one request every 2.4 seconds. It’s possible that you are overwhelming the MongoDB server with too many requests. You can try adding a delay between requests to reduce the load on the server. You can also try and increase the maximum number of connections that your Node.js application can create to the MongoDB server by increasing the poolSize option.

You can also use a MongoDB connection string with a retryWrites option set to true. This option enables your application to retry failed to write operations automatically, which might help in scenarios where the server is temporarily unavailable. Here’s an example connection string with the retryWrites option:


I hope these suggestions help you resolve the issue. If not, it would be good if you can provide your code, sample documents, and logs.