Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High CPU consumption in v4.6 due to a TCP/IP stack implementation bug #5505

Open
4 of 6 tasks
ameshkov opened this issue Nov 7, 2024 · 134 comments
Open
4 of 6 tasks

High CPU consumption in v4.6 due to a TCP/IP stack implementation bug #5505

ameshkov opened this issue Nov 7, 2024 · 134 comments

Comments

@ameshkov
Copy link
Member

ameshkov commented Nov 7, 2024

Please answer the following questions for yourself before submitting an issue

  • Filters were updated before reproducing an issue
  • I checked the knowledge base and found no answer
  • I checked to make sure that this issue has not already been filed

AdGuard version

v4.6.4 (204)

Environment

  • brand = samsung
  • manufacturer = samsung
  • model = SM-A256B
  • version = 14
  • security_patch = 2024-10-01

HTTPS filtering

  • yes, I do

Root access

  • yes, I have it

Integration with AdGuard VPN

  • yes, I do

Routing mode

Local VPN

Ad Blocking

No response

Privacy

No response

Social

No response

Annoyances

No response

Security

No response

Language-specific

No response

Other

No response

Which DNS server do you use?

DNS protection disabled

DNS protocol

None

Custom DNS

No response

What Stealth Mode options do you have enabled?

No response

Issue Details

The issue was originally reported by @derKief, check out the logs analysis here:
#5499 (comment)

To sum it up, AdGuard v4.6 consumes several times more than v4.5

Expected Behavior

No response

Actual Behavior

The usage should be more or less the same in v4.5 and v4.6.

Screenshots

No response

Additional Information

No response

@ameshkov
Copy link
Member Author

ameshkov commented Nov 7, 2024

Things to check:

  1. Is it specific to Samsung?
  2. One thing that's unusual compared to regular configuration is that DNS protection is disabled and Android's private DNS is used instead.

@derKief
Copy link

derKief commented Nov 7, 2024

@ameshkov

  • Is it specific to Samsung? My other device that has the same symptoms is also a Samsung -> Galaxy S24 (SM-S921B/DS)

  • One thing that's unusual compared to regular configuration is that DNS protection is disabled and Android's private DNS is used instead. I changed it during the whole troubleshooting because I suspected it, but it makes no difference.

@0xrxL
Copy link

0xrxL commented Nov 7, 2024

I don't know about 4.6, but this is the last stats from Nightly 44:

Screenshot_20241107_205512_AdGuard
Screenshot_20241107_210350_Device care

and CPU foreground usage is weirdly high, despite system battery usage is 1.6%.

@0xrxL
Copy link

0xrxL commented Nov 7, 2024

@ameshkov Can this usage related to this issue in any way?

P.S: I have a S23 Plus however.

@ameshkov
Copy link
Member Author

ameshkov commented Nov 8, 2024

@0xrxL if this is a 24-hours usage then it looks good to me.

@derKief on the contrary faces a real issue. We've been trying to reproduce it on Samsung devices yesterday but no success so far.

@ameshkov
Copy link
Member Author

ameshkov commented Nov 8, 2024

@derKief just in case, could you please try nighlty version of AG? It has just minor improvements, but for some reason we don't see reports from Samsung owners on the nightly build (and the two I saw on GH seem to have normal usage).

@abryant-hv
Copy link

abryant-hv commented Nov 8, 2024

Ever since at least 4.6.4, Adguard has been the top consumer of battery life on my (Samsung) phone every time I've checked, with no change in my usage of the phone. I'll try the nightly today, but 4.6.204 definitely did not fix the issues. And yes, I have sent the logs to support, but I got an email this morning closing the ticket, with no other information.

I don't want to just pile on this ticket with a useless comment, but this issue is definitely not resolved with 4.6.204.

@PavelParkhomenko
Copy link

PavelParkhomenko commented Nov 8, 2024

And yes, I have sent the logs to support, but I got an email this morning closing the ticket, with no other information.

We responded to you yesterday in ticket #978524 before closing it. In our response, we informed you that the app logs were forwarded to our development team and provided a link to this issue so you can track further progress.

@abryant-hv
Copy link

Yes there was a link to this issue, which is why I'm here. It sounded above like victory was being declared a bit too early, but perhaps I misread that.

Back on topic, I've used the v4.7 Nightly 44 this morning for about 3 hours, and AdGuard has used 19.1% of my battery in that time, 3 times more than the next app. Device battery usage is still higher than normal with the latest nightly. :(

@ameshkov
Copy link
Member Author

ameshkov commented Nov 8, 2024

@abryant-hv what exact Samsung model are you using just in case?

@abryant-hv
Copy link

It's a "Galaxy A52 5G". Model name is "SM-A526U"

@derKief
Copy link

derKief commented Nov 8, 2024

with the Nightly 44 (4.7.89) it has gotten better but in direct comparison to the stable 4.5 it is still too high/much.
Tested with the SM-A256B (Galaxy A25). My other phone the Galaxy S24 is still on v4.5 and will remain so until the problem is resolved.

@ameshkov I replied to your private e-mail. Waiting on feedback.

@derKief
Copy link

derKief commented Nov 9, 2024

Today I tried to update to the new 4.7 Nightly 45, but it didn't work. The app crashed and wouldn't start anymore.
Since I don't really have the time to do any more error analysis, I've gone back to the stable version 4.5, which works
without any problems. Hopefully this is fixed soon ....

@0xrxL
Copy link

0xrxL commented Nov 9, 2024

Today I tried to update to the new 4.7 Nightly 45, but it didn't work. The app crashed and wouldn't start anymore. Since I don't really have the time to do any more error analysis, I've gone back to the stable version 4.5, which works without any problems. Hopefully this is fixed soon ....

Mhh...weirdly in my case the Nightly 45 (at least for the moment) seems to be very optimised. Check it out here:

Screenshot_20241109_173142_Device care

@Cb1231ct
Copy link

Cb1231ct commented Nov 9, 2024

Had this been fixed yet. I had to turn it off the drain was so bad. Where can I find 4.5th go back to it

@jordansworld
Copy link

no. i would just go back to 4.5 for now

@Cb1231ct
Copy link

Cb1231ct commented Nov 9, 2024

Yes where is it to download please

@derKief
Copy link

derKief commented Nov 9, 2024

@solkarnar
Copy link

I know it's a Samsung ticket but i have the same problem on a Xiaomi Phone. I have reverted to 4.5 and will be watching this ticket to see if any solutions manifests itself.

@jordansworld
Copy link

good to know its an all around issue

@muchqs
Copy link

muchqs commented Nov 10, 2024

I don't think the 4.6 build 204 Hotfix version completely fixed the problem. The battery drain caused by the calendar timezone change when phone is idle is gone. However the app still seems to cause very high CPU usage when it's not idle, causing phone to heat up badly and battery goes down insanely fast.

I posted here. The AdGuard battery stat screen shows 24-hour usage is normal, but when I use the phone, CPU temp goes through the roof, approaching around 80C sometimes in as little as 2-5 minutes. And the battery drops super fast. The phone becomes a very effective hand warmer.

I noticed this while using the Bing app and AliExpress app in particular.

I went back to v4.5. Phone still got warm while using those apps but not as much as the v4.6 build 204 Hotfix version.

v4.6 build 204 Hotfix - CPU temp 70-80C while using apps. Temp consistently above 70C with spikes to 80C.

v4.5 - CPU temp 60-70C while using apps. Temp around 60C with a few spikes to 70C.

phone is Vivo X100 Pro.

@derKief
Copy link

derKief commented Nov 10, 2024

I know it's a Samsung ticket but i have the same problem on a Xiaomi Phone. I have reverted to 4.5 and will be watching this ticket to see if any solutions manifests itself.

I can now confirm that this is not just a Samsung problem. My wife's Poco X6 Pro is also affected and here too we are back to v4.5

@0xrxL
Copy link

0xrxL commented Nov 10, 2024

Heh...Unfortunately, today the latest Nightly started to drain my battery again, and this after starting to watch a TV series from web browser. This problem didn't happen during normal navigation, maybe this can helpful to find the root of problem @ameshkov?

@unknown4849
Copy link

Xiaomi (poco F6) too. i first think my devices broken XD. after restart and start adguard seem fine.

security patch same 2024-10 -1, could this be the cause? i feel before update to this patch don't have this problem, but after update at today i got this problem CPU locked at high speed (via CPUZ)

@muchqs
Copy link

muchqs commented Nov 11, 2024

I don't think the 4.6 build 204 Hotfix version completely fixed the problem. The battery drain caused by the calendar timezone change when phone is idle is gone. However the app still seems to cause very high CPU usage when it's not idle, causing phone to heat up badly and battery goes down insanely fast.

I posted here. The AdGuard battery stat screen shows 24-hour usage is normal, but when I use the phone, CPU temp goes through the roof, approaching around 80C sometimes in as little as 2-5 minutes. And the battery drops super fast. The phone becomes a very effective hand warmer.

I noticed this while using the Bing app and AliExpress app in particular.

I went back to v4.5. Phone still got warm while using those apps but not as much as the v4.6 build 204 Hotfix version.

v4.6 build 204 Hotfix - CPU temp 70-80C while using apps. Temp consistently above 70C with spikes to 80C.

v4.5 - CPU temp 60-70C while using apps. Temp around 60C with a few spikes to 70C.

phone is Vivo X100 Pro.

I downgraded even more today to v4.4.1 as I find even with v4.5 the CPU temp seems rather elevated.
And initial results show that indeed, v4.4.1 is better than v4.5.

Before testing v4.4.1, CPU temp was 100% under 40C.
After using AliExpress app for around 15 min, CPU temp was 100% above 40C, but also all under 50C except one single spike to 50C.
Used the Bing app for 14 min. CPU temp was still consistently between 40C to 50C, never above 50C.

on v4.5, after using the same apps, CPU temp would be between 60-70C.

so far my results:
v4.6 hotfix - CPU temp 70-80C
v4.5 - CPU temp 60-70C
v4.4.1 - CPU temp 40-50C.

gonna do the same tests again tomorrow.

@ameshkov
Copy link
Member Author

@0xrxL why do you think it's a "drain" and not a normal usage? Did it stop after you finished watching? Is it specific to that website?

@ameshkov
Copy link
Member Author

ameshkov commented Nov 11, 2024

@muchqs tbh temperature numbers do not provide us with any insights into the issue.

AdGuard prints CPU usage numbers measured by the system, it'd be helpful if you compare them between different versions.

Basically, we need every record in the log that contains Calculated battery usage (it's printed to the normal INFO log as well). I explained them here: #5499 (comment)

@jordansworld
Copy link

Nightly 1 doesn't include the fix.

@0xrxL
Copy link

0xrxL commented Dec 5, 2024

@derKief @jordansworld @sk1llsh0t Nightly 3 with the new fixed CoreLibs is available. Try it. 👍

@jordansworld
Copy link

thankyou for your hardwork!

@sk1llsh0t
Copy link

Unfortunately for me the nightly 3 build did not fix the problem. It still consumes 14%+ cpu and 20% battery consumption.

@ameshkov
Copy link
Member Author

ameshkov commented Dec 6, 2024

@derKief thanks for your help! I understand that it is annoying and we're trying to figure it out.

Some 4.7 nightlies that I tested did it better. I don't understand it and hope that a solution will finally be found.

The bad thing here is that I don't understand it either.

We stopped at the very same point - we identified the place where the TCP packet is getting stuck. We then added some extra logging there, but so far no one was able to send us a log file where the issue was reproduced.

The only difference between stable and nightly is having this extra logging.

Folks, I have to say it again: we are not able to reproduce it on our devices, we need debug-level logs to figure it out. Ideally, from the latest nightly version.

At this point the procedure is rather simple:

  1. Enable debug-level logging
  2. Wait until the issue happens again
  3. Export logs, send them to devteam@adguard.com

@derKief
Copy link

derKief commented Dec 6, 2024

@ameshkov I realize that you are trying to solve the problem, but this constant back and forth is not nice and takes time.

I've now tried another test and installed 4.8 nightly 3. So far everything is fine and there are no problems. The last time I installed stable 4.7, the problem was immediately apparent. So I can't understand why the only difference between stable 4.7 and 4.8 nightly 3 is the extended logging.

I'll leave it like this for now and continue to observe.

@ameshkov
Copy link
Member Author

ameshkov commented Dec 6, 2024

@derKief this difference makes me believe that we're dealing with a race condition that is very sensitive to timings, the worst kind. Adding extra logging to these functions adds a microsecond-delay and this improves the situation and makes the issue happen less often. It does not mean that the issue is fully fixed, it should manifest itself eventually.

Some people in comments were saying that they're having that issue on the nightly version too, maybe they can help.

@sk1llsh0t @jordansworld if you can reproduce this with the nightly build, please try collecting the debug log.

@sk1llsh0t
Copy link

I've set debug logging on. I'll let it run a bit (until the issue appears). Do i just send the log in through the report a bug option in the app or is there another way you prefer to get it?

@ameshkov
Copy link
Member Author

ameshkov commented Dec 6, 2024

@sk1llsh0t it'd be better if you export the full log via the app and then send an email to devteam@adguard.com. Please mention that it's related to this Github issue.

@sk1llsh0t
Copy link

Logs sent.

@derKief
Copy link

derKief commented Dec 6, 2024

Short interim report with 4.8 nightly 3:

  • no problems with high load or high frequency on the CPU cores
  • no problems with high temperatures.
  • The battery consumption is still too high though. In the Adguard statistics you can clearly see that the background usage is much too high.

I'll let it run until tomorrow but it seems that the problem still exists, although not as extreme as with the stable versions 4.6 and 4.7

@jordansworld
Copy link

got the best battery usage ive had in a while. 8hr 15min at 20 perceng.
Screenshot_20241206_190100_Device care
Screenshot_20241206_190138_Device care

@derKief
Copy link

derKief commented Dec 7, 2024

Final conclusion:
in direct comparison with my Galaxy S24, which is still running the stable version 4.5, the Galaxy A25 with 4.8 nightly 3 consumes twice as much battery (based on the Adguard in-app statistics). And that despite the fact that the S24 is used much more.
In my case, the high battery consumption remains.
Back to Stable 4.5

@0x4a4700
Copy link

0x4a4700 commented Dec 8, 2024

I have the same issues (high battery drain) with my Galaxy S23 Ultra (latest updates applied).
It started with 4.6, was already in contact with support (
#980394) and thought it was fixed during some nightly I tested, but then upgraded to more recent nightlies and the issues came back with 4.8 build 3 :(
I reverted back now to 4.7 stable and my phone nearly died over night in flight mode because of battery drain of Adguard.

Where can I download specific nightly apk versions?

I need especially version 4.7 nightly 48 or later 53 which seem to have worked for me (later on, especially with 4.8 nightly it started again)

@derKief
Copy link

derKief commented Dec 12, 2024

Any news here ? Anyone tried new stable 4.7.1 ?

Changelog is somehow not very informative:
- In this update we've improved the stability of the app and fixed some minor bugs.

And what about 4.8 Nightly 4 ?

@sk1llsh0t
Copy link

Nightly 4 has the same issue

@slythrn
Copy link

slythrn commented Dec 15, 2024

Any news here ? Anyone tried new stable 4.7.1 ?

Changelog is somehow not very informative: - In this update we've improved the stability of the app and fixed some minor bugs.

And what about 4.8 Nightly 4 ?

I'm still having issues on my Motorola and Pixel phones with the latest stable version.

@solkarnar
Copy link

@ameshkov Any updates sir?

@derKief
Copy link

derKief commented Dec 21, 2024

Has this topic died down or why has there been no update or statement for days?

@solkarnar
Copy link

Has this topic died down or why has there been no update or statement for days?

probably holidays and people being away with their families.

@derKief
Copy link

derKief commented Dec 21, 2024

pretty sure ... but a short status update before the holidays would have been nice

@ameshkov
Copy link
Member Author

Sorry, yeah, holidays indeed mess with us.

Merry Christmas to everyone!

@sk1llsh0t thanks for sending the logs! I may be wrong, but from the log it looks like you have quite a lot of statistics. Am I right? This looks like a legit issue to me, but again it's unrelated to the one I saw in @derKief's logs.

I'll return tomorrow with some specifics.

@ameshkov
Copy link
Member Author

ameshkov commented Dec 26, 2024

@sk1llsh0t confirmed the issue. Temporary solution: clear statistics, the situation will normalize. Proper solution will be ready later.

@sk1llsh0t
Copy link

When I tap on the stats tab, I just see 3 green dots in the middle of the screen and nothing loads. The app appears to freeze. I'm not sure how to clear stats without going to that tab. Maybe I'll just wait for the fix to be released.

@ameshkov
Copy link
Member Author

@sk1llsh0t you may need to wait for quite some time until the stats are loaded or clear the app data.

Here's the explanation for the issue: AdGuard at startup goes through statistics and tries to "compress" it, i.e. merge records for the old dates. There's a bug in this algorithm that may lead to the issue that you're having.

@derKief
Copy link

derKief commented Dec 27, 2024

@ameshkov
Is there an update on the actual topic here? Has the cause or trigger been identified in the meantime?
Version 4.5 is slowly becoming outdated.

@ameshkov
Copy link
Member Author

@derKief no update unfortunately.

So far your's are the only case where we saw that issue and unlike @sk1llsh0t's issue we cannot reproduce it. With @sk1llsh0t's we've been able to "generate" statistics database that causes the issue, but with this TCP issue we failed despite trying different ways to overload the TCP stack.

What makes it really problematic, it seems that enabling debug-level logging resolves your issue. It may sound strange, but it sometimes happens, it's enough to introduce a slightest delay.

Because of that we'll have to resort to ugly solutions: instead of asking you to collect debug-level log we'll try to detect the problematic condition and crash the app when it happens (and at that point we'll log everything required to troubleshoot it further). This change will come in one of the following nightlies, I'll announce it here.

One more thing: thank you so much to everyone that's helping us figure this all out, I don't think we could manage without you!

@0x4a4700
Copy link

0x4a4700 commented Dec 27, 2024

I also still have the issue in the latest nightly, with nearly 30% battery usage, also over night when in flight mode... I have asked three weeks ago if there are any apks for previous nightly builds?

@ameshkov
Copy link
Member Author

@0x4a4700 which one do you need?

Could you please collect log as described here?
#5505 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests