Facing issue "too many open files" with all versions of MongoDB on Apple M2

Hi there,

I recently changed my system to Apple Mac Pro M2 on latest MacOS 13.3.1.
I’m able to install MongoDB successfully, but whenever I’m trying to mongorestore from a dump on my local, I’m always facing either of these issues:
1.Failed:<collection_name>: error creating collection <collection_name>: error running create command: (TooManyFilesOpen) 24: Too many open files - where <collection_name> is random every time. or,
2. Failed:<collection_name>: error reading database: connection() error occurred during connection handshake: connection(localhost:27017[-8]) socket was unexpectedly closed: EOF

Mostly it’s “too many open files” and in this restore process few or more collections get missed and service also gets stopped.
I tried all 4.4.19, 5.0 and 6.0 versions of MongoDB. All results in same. My current database tools version is 100.7.0 and file descriptors value is 64000 “ulimit -S -n 64000” in .zshrc.

I also realised that the service also itself gets stopped when I’m just using Compass to access DB.

Can anyone please provide any help on it? I’m starting to believe that this is related to M2 chips only.

1 Like

I was able to fix it by running
sudo launchctl limit maxfiles 64000 524288

but since this maxfiles limit was being reset on system reboot. I had to create a file /Library/LaunchDaemons/private.maxfiles.plist with following code

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
    <dict>
        <key>Label</key>
        <string>private.maxfiles</string>
        <key>ProgramArguments</key>
        <array>
            <string>launchctl</string>
            <string>limit</string>
            <string>maxfiles</string>
            <string>64000</string>
            <string>524288</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
    </dict>
</plist>

This created a daemon so that on system boot it can set the maxfiles limit. My belief is that this problem is only with M2 systems, because I have many colleagues who’re using an M1 mac and no one had ever faced such issue with same open files or maxfiles limit.

In case if someone has better explanation do let me know. Thanks!

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.