Frequent "cannot allocate memory" errors during HTTP requests in scripts

I'm on an M2 air with Sonoma 14.4.1. I frequently see errors mentioning "cannot allocate memory" while using tools that make HTTP requests from the command line. I first experienced it with my code and thought I had a memory leak, but I was never able to identify and fix one, then I started noticing it with major CLI programs. Concrete example:


> gh status

failed to search: could not search for assignments: Post "https://api.github.com/graphql": dial tcp 140.82.116.5:443: connect: cannot allocate memory


The error has occurred with gh, gcloud, as well as my own node and python scripts. It seems to be a lower level problem with the OS networking layer than something in these tools. There is no discernible pattern to when they occur. They persist after restarts. Sometimes repeating the same command works. If a command makes many HTTP requests, however, it almost always eventually emits a memory error, though at unpredictable points.


Is this just an OS error and I have to wait for an update? Is there any many to free up memory for network requests? Activity Monitor shows my memory nowhere near maxed out when the errors happened. I've also tried closing all other running applications but the error still occurs. It seems to have nothing to do with the actual resources available.


[Edited by Moderator]

MacBook Air (M2, 2022)

Posted on Apr 17, 2024 12:37 PM

Reply

Similar questions

2 replies

Apr 18, 2024 4:39 AM in response to phette23

When running scripting tools, you are so far away from any actual memory allocation commands that any error message to that effect is meaningless.


You would have to try to find some sequence that can reliably generate the error. Then, enable any and all debugging options. No guarantees, of course.


Also, you've mentioned "gh", "gcloud", "node", and your own scripts. None of these are Apple tools. You are far, far away from demonstrating any Apple cause. For all I know, you're using Homebrew. If so, just give up.


And finally, I don't intend to dismiss your suggestion that it is an OS error. It could very well be an OS error. You are running macOS 14.4.1. Why? I have a similar M2 Air and I'm not even running the latest version of Ventura. I just noticed the other day that there are reports of problems with 13.6.6. So this isn't really a specific Apple problem, or a specific 3rd party app problem. It's more a general problem with our internet and update addicted society. If Apple developers, making over $100k/year, can't release an update without major bugs, what makes you think that developers making $0/year would fare any better? You have to be more aggressive and brutal when applying updates. The ideal time to apply an update is before one is released, maximizing the time since the previous update. Even minor updates can cause problems. What do you gain from that? Protection against fantasy hackers from North Korea? Don't make decisions based on misinformation spread on the internet.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Frequent "cannot allocate memory" errors during HTTP requests in scripts

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.