I am working on an open source Ruby on Rails project with a full suite of rspec tests. The tests work normally on the CI/CD pipeline server, but locally on my MacBook running Monterey they fail intermittently. Sometimes zero tests will fail, sometimes a handful, sometimes hundreds — all with no code changes.
The error messages
The intermittently failing tests produce a variety of errors:
Errno::EMFILE:
Failed to open TCP connection to 127.0.0.1:9520 (Too many open files - socket(2) for "127.0.0.1" port 9520)
The above error appears with various port numbers. I have spotted 9515, 9517, 9518, 9520, 9522, 9529, 9533 and 9536.
I'm also seeing a lot of other errors that complain of too many open files:
Failure/Error: Capybara::Webmock.start Errno::EMFILE: Too many open files
Errno::EMFILE: Too many open files - rackup
Errno::EMFILE: Too many open files - /Users/username/.webdrivers/chromedriver
I think it likely that a single issue underlies all these intermittent errors. Search results for a lot of these errors lead to Chromedriver, Selenium, Capybara, and WebMock.
What I have tried
I have increased the number of available file descriptors with ulimit -Sn 61440
Increased the files available to launchctl limit maxfiles
I have checked that my chromedriver -v corresponds to the Chrome browser version installed on my MacBook
I have cleared caches by running bundle exec rails tmp:clear and Rails.cache.clear, and by setting the Cache-Control header to public, no-cache, must-revalidate and other settings
I have added net_http_connect_on_start: true to my WebMock configuration, per their documentation
I have tried killall chromedriver to ensure there isn't a zombie chromedriver process
My code
My WebMock configuration should allow local connections as it includes the following:
require 'webmock/rspec'
WebMock.disable_net_connect!(
allow: [
/localhost/,
/127\.0\.0\.1/,
/codeclimate.com/, # For uploading coverage reports
/chromedriver\.storage\.googleapis\.com/, # For fetching a chromedriver binary
],
)
My Capybara configuration is here.
To answer my own question, I increased the available macOS file descriptors to solve this problem. MacOS apparently does not take you seriously when you increase the ulimit from the command line; it demands a configuration file and a restart.
I'm not convinced I found the underlying issue — I suspect there may be some problem in my configuration causing file descriptors to be exhausted. Perhaps there are some connections that aren't being property closed. Yet, increasing the limit solves the immediate problem.
I created a property list file owned by root:
sudo nano /Library/LaunchDaemons/limit.maxfiles.plist
I paste this text into the file:
<?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>limit.maxfiles</string>
<key>ProgramArguments</key>
<array>
<string>launchctl</string>
<string>limit</string>
<string>maxfiles</string>
<string>524288</string>
<string>524288</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>ServiceIPC</key>
<false/>
</dict>
</plist>
I saved the file. Just to be sure, I printed the file to the terminal with cat to confirm it exists. And I checked ls to ensure that root wheel owned the file.
cat /Library/LaunchDaemons/limit.maxfiles.plist
ls -la /Library/LaunchDaemons/limit.maxfiles.plist
I restarted my MacBook to cause the .plist to take effect. Then I checked the file descriptor limits again with:
ulimit -n
launchctl limit maxfiles
Both now return a limit of 524288. The "too many open files" messages are gone.
Further reading:
El Capitan ulimit shenanigans by Dejan Kitic
"Too many open files" limit/ulimit on Mac OS X by Thomas Jung
Ruby 2.7.1 - Errno::EMFILE: Failed to open TCP connection to 127.0.0.1:9*** (Too many open files - socket(2) for "127.0.0.1" port 9***) by ndbroadbent
Related
I have an application that consists of two parts: Python (the main app, which works as a server) and Electron ("helper" app, which works as a UI).
I plan to submit it to the App Store, so it's sandboxed.
Right now, I'm testing the sandboxed development-signed build, and I have a problem with it.
Some info about the entitlements and signing:
The Python app is packaged with Py2App (I heard that it's the only possible way to package a Python app for the App Store).
The Python app has com.apple.security.network.client, com.apple.security.network.server, and sandbox entitlements, I sign it using the Mac Development certificate.
The Electron app is packaged with electron-builder and signed with electron-osx-sign (Mac Development certificate, as well).
The Electron app has standard entitlements, I just added the sandbox and security.inherit to its entitlements.
I have generated the development provision profile and embedded it into the app's bundle.
Yes, I know that this architecture is a bad choice for the macOS/App Store, I'm aware of it.
The project is 99% done, and it's just easier for me to somehow overcome this issue, rather than rewriting everything from zero to Swift/Obj-C.
So, when the user clicks on the .APP, this is what happens:
the Python app starts, it creates the server, and finally, launches the Electron.
The problem begins here: the Electron successfully starts but fails to load the server's URL.
I tried to open my server's URL in Chrome and everything works fine.
So this problem is related to the Electron or maybe entitlements.
I also tried to load any other webpages, like google.com, and it still doesn't work, I get the exact same error.
When I load the page (like calling the app.loadURL or changing the window.location.href), these messages get printed out in the Console:
default 13:36:40.749975 +0200 trustd cert[2]: AnchorTrusted =(leaf)[force]> 0
default 13:36:42.903489 +0200 symptomsd rssi (-49) or transmitRate (145.000000) changed on interface en1 for BSSID:b0:95:75:21:bc:d8
default 13:36:50.909786 +0200 symptomsd rssi (-50) or transmitRate (145.000000) changed on interface en1 for BSSID:b0:95:75:21:bc:d8
default 13:36:51.321708 +0200 trustd could not enable test hierarchy: no UAT pinning preferences set
I googled this "no UAT pinning preferences set", and didn't find anything useful.
These messages are always the same, it doesn't matter if I try to open a localhost page or google.com.
I also tried using "fetch" in the Electron's app console, it outputs this error:
>>> await fetch("https://google.com")
---> VM123:1 GET https://google.com/ net::ERR_NAME_NOT_RESOLVED
---> VM123:2 Uncaught TypeError: Failed to fetch
---> at <anonymous>:1:7
I think that this issue is somehow related to security.inherit entitlement.
Maybe when I launch the Electron, Python's entitlements don't get passed to the Electron?
So, Electron doesn't inherit the "com.apple.security.network.client" entitlement and has no right to load any web pages, am I right?
If yes, then how should I properly launch the Electron?
Currently, I tried using the "open" command and an AppleScript, the error stays the same in any case.
Here are the commands I used:
Open:
open "MyPythonApp.app/Contents/MacOS/MyElectronApp.app"
AppleScript:
osascript -e "tell application \"MyPythonApp.app/Contents/MacOS/MyElectronApp.app\" to activate"
I sign the Python app with these entitlements:
<?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>CFBundleIdentifier</key>
<string>com.abtco.myquickmaclite</string>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.server</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.files.downloads.read-write</key>
<true/>
<key>com.apple.security.assets.pictures.read-write</key>
<true/>
<key>com.apple.security.assets.music.read-write</key>
<true/>
<key>com.apple.security.assets.movies.read-write</key>
<true/>
</dict>
</plist>
And the Electron app with these ones:
<?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>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.inherit</key>
<true/>
</dict>
</plist>
Mac Mini 2012 (macOS 10.13.6)
Python 3.9.1
Electron 16.0.5
Thank you.
I know this question can be found a lot of time on this forum and the internet. But I can't seem to find the answer to my specific question.
I'm running a Drupal website, and since the update of MAMP from 5.5 to 5.6 I get the following error:
Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) when running a composer require in the terminal.
I updated the php.ini tot 1024MB instead of 128MB of the current php version I'm running via MAMP. When I add a php file to my root with <?php phpinfo(); ?> I see that the memory is like I want so 1024MB. When I look at the location of the php ini file I see it is in the MAMP folder.
But I still get the error. When I run this php -r "echo ini_get('memory_limit').PHP_EOL;" in my terminal I see the 128MB again. When I try to find the php ini that is running using
php -i|grep 'php.ini' I get:
Configuration File (php.ini) Path => /etc
So it looks like the php.ini file is somewhere else. But I don't know where and can't change it. How can I solve this?
I also tried changing the composer memory using php -d memory_limit=-1 /usr/bin/composer but this didn't solve the problem either.
My question is, how can I solve this problem? How can I find the php.ini file that is used. Or how can I change the memory limit?
Update:
Running php -i | grep 'Configuration File' in the terminal ouputs:
Loaded Configuration File => (none)
And maybe good to know that I have the option Make this version available for command line enabled on the MAMP php section.
I tried many of the suggestions on this and a few other stack overflow questions but couldn't get it to work until I tried:
COMPOSER_MEMORY_LIMIT=-1 composer require 'yourpackagenamehere'
Just trying COMPOSER_MEMORY_LIMIT=-1 by itself before running the command didn't seem to work. Not sure why, but I had to run them on the same command line in a similar way as documented in the composer troubleshooting: https://getcomposer.org/doc/articles/troubleshooting.md#memory-limit-errors
I ended up adding a php.ini file to the /etc folder on my computer. This way the php memory_limit raise did work. And checking it in the terminal did show me the right value. But as Alister already said, this didn't fix the problem. The problem was not in the php.ini memory_limit.
I found out that using COMPOSER_MEMORY_LIMIT=-1 in the terminal at the beginning of my session put the memory limit to unlimited during that terminal session. This fixed the problem.
After that I added, alias composer="COMPOSER_MEMORY_LIMIT=-1 composer" to my bash file and know everything is working like I would expect.
Changing the amount of memory in php.ini won't help - that is the limit for what is being used by the webserver's version of PHP - and having too much available for the webserver can cause problems (at least when running in production).
Composer, when it is being run from the command line, will, by default set the limit to 1,610,612,736 bytes - 1.5 GB.
As you are apparently still on PHP 5.6, that's also a very considerable problem. PHP 7+ is a great deal more efficient with memory, as would be an up to date version of composer.
Finally, to actually solve the problem: Restrict your requirement to be more specific since that keeps memory usage lower.
I am raising this problem again and again on my live server. Please help me out with the problem. My project is on windows so how I can increase the limit on windows.
I have seen the solution but this is given for Ubuntu. How I can do the same on windows?
EMFILE is too many files opened in your process.
ENFILE is too many files opened in the entire system.
So Errno::EMFILE is due to the ruby process opening too many files. This limit is probably set to the default 1024 can be seen with:
$ulimit -n
1024
Instead of:
$ulimit
unlimited
The error I'm seeing is as follows:
Test target PrototypeTests encountered an error (The operation couldn’t be completed. Too many open files in system. Too many open files in system)
Test target Prototype Integration Tests encountered an error (The operation couldn’t be completed. Too many open files in system. Too many open files in system)
I am able to run the analyze and archive actions with no problems but enabling the test action causes the above errors. I've even tried this with empty tests and the problem still persists.
The output of sudo launchctl limit maxfiles on my server is:
maxfiles 256 unlimited
Please let me know if I can provide any more information.
You need to increase your ulimit. You should add the line:
ulimit -n 4096
in your ~/.profile or similar.
The reason you have to add this line to your bash launch file is because just running sudo ulimit -n 4096 will only change the limit in current bash session.
I received this same message while trying to compile while low RAM, low disk space, and many open apps & files on my desktop. Closing most of them and emptying the trash resolved the issue.
I'm building my iOS projects from a jenkins slave and getting some weird results. If I try to build my project from the command-line as jenkins does it, there are no problems. But jenkins keeps telling me the identity appears more than once in the keychain. The identity is not duplicated, I checked it a lot of times.
I'm launching the jenkins slave as my user (using sudo -u, ps shows the correct user) from a StartupItem. The signing cert, its private key and the WWDR intermediate certificate are deployed into the System keychain because I cannot access the login keychain launching jenkins from the StartupItem.
After digging a little bit through SO and Google I've found that it could be related to something pointed in this question:
Missing certificates and keys in the keychain while using Jenkins/Hudson as Continuous Integration for iOS and Mac development
I have set a command-line step in order to print the list-keychains output and I'm getting the same:
+ security list-keychains
"/Library/Keychains/System.keychain"
"/Library/Keychains/applepushserviced.keychain"
"/Library/Keychains/System.keychain"
But it is not working for me, xcodebuild keeps saying "Certificate identity 'XXXXXX' appears more than once in the keychain" and seems to be related as I have the System.keychain duplicated in the keychain list.
I cannot find a way to leave just one System.keychain into the list, I tried:
Executing a first script using security list-keychains -s in order to change the list w/o luck
Cleaning all the certs and keys and start over again
Resetting the keychains
Creating a dedicated user for the jenkins service trying to avoid any mess from the previous user, but seems to be something more system-wide related
Resetting LS database
Any clues from anyone?
I tried to leave a comment on the previous mentioned question but I'm a newbie, I can't do it and answering doesn't seems polite as I need to ask something, I'm not giving an answer. So any answer through this question would be appreciated. Thanks in advance!
Environment:
OSX Lion 10.7.3
Xcode 4.3
Xcode command-line tools updated
Jenkins ver. 1.456 and up to date plugins.
Currently, it cannot be done using a StartupItem... I've finally managed the problem using a LaunchDaemon based on an answer from the linked SO. This is the LaunchDaemon I'm using:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GroupName</key>
<string>wheel</string>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>org.jenkins-ci</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/java</string>
<string>-jar</string>
<string>/Users/jenkins/work/slave.jar</string>
<string>-noCertificateCheck</string>
<string>-jnlpUrl</string>
<string>https://MySERVER/jenkins/computer/MacOSX/slave-agent.jnlp</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>jenkins</string>
<key>SessionCreate</key>
<true/>
</dict>
</plist>
So I see that keychain list when I run Jenkins from launchctl as a LaunchDaemon. No matter which user I tell launchctl to use when it launches I always only see only those keychains.
To change this behavior I started Jenkins from a launchd plist as a LaunchAgent. Using Jenkins to list the keychains in this instance shows the users Login keychain and System keychain rather than the slightly odd "System,applepushserviced,System" list.
This can also be fixed by opening Keychain Access, Edit, Keychain List and removing the System keychain from the User list. It's still available from System.