home-assistant / iOS

:iphone: Home Assistant for Apple platforms
https://companion.home-assistant.io
Other
1.55k stars 302 forks source link

Memory leak #2101

Open jedisct1 opened 2 years ago

jedisct1 commented 2 years ago

Device model, version and app version

Model Name: Macbook Pro with M1 Max, macOS Version: MacOS 12.3 App Version: Home Assistant Companion 2022.3 (2022.358) Safari Version: Version 15.4 (17613.1.17.1.6)

Home Assistant Core Version

2022.3.5

Describe the bug

Looks like there's a memory leak.

I've been running the companion app in the background for a few days and the system eventually ran out of memory:

Screen Shot 2022-03-17 at 21 17 01

To Reproduce

Expected behavior

Screenshots

See above.

Additional context

mrwogu commented 2 years ago

+1

poster983 commented 2 years ago

+1 Been happening for me since January

manosioa commented 2 years ago

+1 I have this issue ever since I got the M1 MacBook Pro. The amount of memory allocated by Home Assistant app is insane, Mac's temperature is rising and then there is the battery drain issue.

uninstalled and reinstalled the app with no luck.

poster983 commented 2 years ago

I also have the M1Pro Mac Book Pro so it could be an issue with Rosetta 2?

zacwest commented 2 years ago

The app does not use Rosetta.

Very likely this is an Apple bug in Catalyst apps, but it can be helpful to narrow down what's taking up memory space. You can help debug this by doing a few things when this occurs:

  1. In Activity Monitor, double-click Home Assistant and run "Sample" on it.
  2. On the command line, run leaks <pid> (where is the "process group" number in Activity Monitor)
  3. On the command line, run heap <pid> (same as previous)

Save these files off and attach the text files here.

manosioa commented 2 years ago

Hey @zacwest

Here are my findings as soon as the app was acting out again

Home Assistant Heaps.txt Home Assistant Leaks.txt Sample of Home Assistant.txt

Screenshot 2022-04-13 at 09 55 47 Screenshot 2022-04-13 at 09 55 29
poster983 commented 2 years ago

Thanks @manosioa. Of course the moment I need it to start leaking it doesn't for days

gthrift commented 2 years ago

Happening here as well. Reaches up as much as 55gb. Restarted the app and it immediately went up to 8gb memory usage.

Sample of Home Assistant.txt Home Assistant Heaps.txt Home Assistant Leaks.txt

poster983 commented 2 years ago

Finally.. Here are mine HAHeaps.txt HALeaks.txt Sample of Home Assistant.txt

brianegge commented 2 years ago

Screen Shot 2022-04-15 at 10 17 49 AM

adamfeldman commented 2 years ago

After ~4 hours. Also am on M1 (Max).

leak@2x
zacwest commented 2 years ago

Thanks for all the logs. I have an idea what may be the cause. Do you all have a lot of entities? I think it may be the app keeping track of states - storing a small part of a state change is keeping the entire API response in memory, which means it'll scale fast if you have many frequent state changes.

poster983 commented 2 years ago

I do have a lot of entities. I have a script that essentially starts a “Disco Mode” which very quickly updates all my lights (~50) to random colors. It would always crash the iOS app. So I’ll test this with the macOS app when I get home today.

manosioa commented 2 years ago

I too have a lot of entities. The weird thing is that it can run smoothly for an extended period of time and suddenly starts acting up.

gthrift commented 2 years ago

Yes, I have a lot of entities.

On Fri, Apr 29, 2022 at 3:56 PM Zac West @.***> wrote:

Thanks for all the logs. I have an idea what may be the cause. Do you all have a lot of entities? I think it may be the app keeping track of states - storing a small part of a state change is keeping the entire API response in memory, which means it'll scale fast if you have many frequent state changes.

— Reply to this email directly, view it on GitHub https://github.com/home-assistant/iOS/issues/2101#issuecomment-1113671209, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABB6R6CQ2GFEOQ4MJPSD4KDVHQ5GVANCNFSM5RABXPZQ . You are receiving this because you commented.Message ID: @.***>

skynet01 commented 2 years ago

Same.. lots of entities (about 500) and not only is there an issue with memory I have high cpu usage as well. On both the macOS app and systemstats service.

Not sure why it needs to pull all the entities especially when the app is running in the background. I just need it to send some sensor info to home assistant (if my laptop is running, display connected as well etc).

manosioa commented 2 years ago

Hi!

Any news regarding this? Still having big issues with the App

Zylvo commented 2 years ago

MacBook 13" M1 - macOS 13 dev beta 3 It's started to leak more often compared to macOS 12.

HeySora commented 2 years ago

Can confirm this issue still happens, might be related to putting macOS to sleep mode often, instead of properly shutting down the computer?

manosioa commented 2 years ago

I guess you don't own either a Mac or a modern laptop. You don't have to shutdown the computer. Just closing the lid or in case of an iMac just walking away does the trick. The app should work correctly.

HeySora commented 2 years ago

I guess you don't own either a Mac or a modern laptop. You don't have to shutdown the computer. Just closing the lid or in case of an iMac just walking away does the trick. The app should work correctly.

@manosioa I do own a M1 Pro MacBook Pro, I am affected by this issue (I said so, "Can confirm this issue still happens"...)

I am just the kind of person closing my Mac's lid all the time, my current uptime is near one month.
Since solely using sleep mode is something that I reckon not everyone does, I am not saying using sleep mode is wrong, I tried assisting this issue's resolution by hinting "maybe this is related to sleep mode?" which is something that is commonly overlooked in desktop applications.

Of course the app should work correctly, but not every app does, and maybe it is the issue of this specific memory leak.

d4wud commented 2 years ago

+1

rogersmj commented 2 years ago

Piling on to say this happened to me; within a few days of installing the app (2022.387) my 14" MacBook Pro (M1 Pro, 16GB) ground to a halt and completely died after throwing up the "out of memory" screen. Home Assistant was using just shy of 60GB. As far as my usage pattern, my MacBook stays plugged in at my desk pretty much all the time and goes to sleep when idle.

I saw a theory above that this may be exacerbated by having lots of entities....and I have a lot of entities (don't know how many exactly, but many many hundreds, probably around 1000).

qbunt commented 2 years ago
image

Also seeing the same on M1 Max. I will say the worst part of this is seemingly the only way to recover is to reboot the machine. Definitely on a high number of entities like the rest of the thread.

skynet01 commented 2 years ago

Can't you just kill the HA process without having to reboot? Also I think you are the top winner for the most ram usage screenshot. Let's see if anyone can beat it!

qbunt commented 1 year ago

@skynet01 I don't think Activity Monitor catches everything it should and the system feels really sluggish until a reboot. It's super odd, I'm not going to use it on my daily driver until this is fixed, it's kind of dangerous.

TychoWerner commented 1 year ago

Got the same, seems to happen when it loses connection to HA.

johandijkstra commented 1 year ago

Hi al, I have the same issue

image

Apple M1 Pro - MacOS 13.0 (22A380)

progrmr commented 1 year ago

Interesting my Force Quit menu doesn't show any memory sizes. Sounds like this problem is only happening on M1 / M2 Macs? My Activity Monitory shows HA is only using 43 MB. (my Mac has an Intel i7)

Screen Shot 2023-01-02 at 16 07 23
qbunt commented 1 year ago

Maybe this needs some attention now that Reddit has taken notice. Does this need more diagnosis?

stuible commented 1 year ago

Also running into this issue on MacOS 13.4 and Home Assistant 2023.6.2

manosioa commented 1 year ago

More than a year later, the issue persists

jtrumpio commented 1 year ago

New high score?

image

I'm setting a calendar reminder so I can bake this issue a 2 year birthday cake next March.

Seriously tho, what do we need to do to get some traction on this?

M1 Max MacbookPro

Companion App is 2023.4 (2023.460) on macOS Ventura 13.5.1

Server is 2023.8.3

There is nothing useful in the companion logs.

I just updated to the latest public beta of Sonoma (14.0) to see if that helps.

parautenbach commented 1 year ago

Memory usage: 113MB.

MacOS: Ventura 13.4

Companion app: 2023.4 (460)

Server: 2023.7.1

I haven't rebooted this iMac recently.

qbunt commented 1 year ago

@jtrumpio I want a slice of that 🍰, I got you beat mate

https://github.com/notifications?query=repo%3Ahome-assistant%2FiOS#issuecomment-1235633775

image

Also seeing the same on M1 Max. I will say the worst part of this is seemingly the only way to recover is to reboot the machine. Definitely on a high number of entities like the rest of the thread.

HeySora commented 9 months ago

Issue still persists :(

image

jtrumpio commented 9 months ago

It still happens to me as well. It sucks there's no movement on this, or feedback from the developer to help us understand what the issue may be if it's not a bug.

lochstar commented 5 months ago

Was using 70GB for me today 👎🏻

jtrumpio commented 5 months ago

Ah crap, I missed baking this issue a 2 year birthday cake in March.

bgoncal commented 5 months ago

Just checking, any of you experiencing this on 2024.4 (or beta 2024.4.1)?

lochstar commented 5 months ago

@bgoncal Haven't tried 2024.4 beta. Where do I get it?

bgoncal commented 5 months ago

@bgoncal Haven't tried 2024.4 beta. Where do I get it?

2024.4 is in App Store, 2024.4.1 is the current beta that you can find here: https://testflight.apple.com/join/1AlPbnLZ

bgoncal commented 5 months ago

There is a special testflight build that Zac and I prepared intended to fix this memory issue (2024.639), could you all try it out and share the results?

the-tylermason commented 5 months ago

This is a screenshot from two days ago. Version 2024.4.

Using nearly 94GB of Memory even though my Mac doesn't have that much to begin with.

Machine: 16" MacBook Pro // M2 Max (12c CPU / 38c GPU) // 32GB Memory // macOS Ventura 13.6.6

Screenshot 2024-04-13 at 1 40 42 AM

bgoncal commented 5 months ago

@the-tylermason Please try this specific TestFlight version 2024.639

Btw what is being used is virtual memory, that's why you see a higher number than what you have physically available

bgoncal commented 5 months ago

@lochstar @HeySora @qbunt @manosioa @jedisct1 Can I count on you to help us test this version too? Let us know your findings. Please try this specific TestFlight version 2024.639

spitfire commented 5 months ago

@lochstar @HeySora @qbunt @manosioa @jedisct1 Can I count on you to help us test this version too? Let us know your findings.

Please try this specific TestFlight version 2024.639

I would love to, but TestFlight stopped working for me and many other people starting with the .4 release of current macOS version

bgoncal commented 5 months ago

@spitfire Can you elaborate? What is not working?

spitfire commented 5 months ago

@spitfire Can you elaborate? What is not working?

TestFlight app on macOS, not HA app. I know it is affecting more people than me (see https://mastodon.macstories.net/@johnvoorhees/112247333443723027), supposedly it started happening in macOS 14.4 (checks out for me), so I am unable to update any apps via TestFlight, regardless of the network I'm connected to.

Zrzut ekranu 2024-04-17 o 14 29 37
bgoncal commented 5 months ago

@spitfire Can you try this? https://drive.google.com/file/d/1X3TbVp92_dDEnXxjfH9kcKimvecUsyg5/view?usp=share_link

(You will have to kill the HA app you already have installed before opening this)