Bug #1136
closedSometimes a new tab is created without a corresponding new page
0%
Description
I've PB Version 3.16 running on lineageOS and when opening an additional website, there're some open, via link, only an empty page raises and the "X" closes PB completely.
Files
Updated by Soren Stoutner 11 months ago
- Priority changed from 3.x to Next Release
This is likely a crash of some sort. Can you please attach a logcat?
Updated by Soren Stoutner 11 months ago
By the way, you can get a Logcat from the Navigation menu inside Privacy Browser.
Updated by Lasse Gismo 11 months ago
VoilĂ
Updated by Soren Stoutner 11 months ago
- Subject changed from Behavior on opening additional links to Opening a link in a new tab opens empty page, which crashes when closed
- Status changed from New to Feedback
This might have the same underlying cause as Bug #1134: Sometimes the tab after a new tab in the middle of a list is set as active, but I am not completely sure what the issue is in either case. I will have to spend some time digging into it.
Does this problem happen every time you open a link in a new tab or only sometimes?
Updated by Lasse Gismo 11 months ago
Damn demonstration effect :-)
No, not allways, last 5 openings ran smoothly.
Will come back after next occurance(s) with new logcat.
OK?
Updated by Soren Stoutner 11 months ago
That logcat is sufficient as it shows the crash clearly. I just needed to know if this always happened, as that indicates what the underlying cause is. In this case, with it being intermittent, the most likely cause is a race condition between the creation of the tab and the WebView that leaves the system out of sync, but I am not yet certain where that is occurring.
Updated by Soren Stoutner 11 months ago
You won't be able to reproduce it consistently. It is what is called a race condition, which means that two things are happening simultaneously in the background (a race). If one finishes first, everything is fine. If the other finishes first, there is a crash.
Race conditions are very tricky because sometimes they only manifest on certain hardware or on certain versions of Android or under other conditions that make them hard to replicate. Among other things, that can make it hard to know when you have fixed them.
Updated by ask low 11 months ago
Maybe the implementation of opening new tabs as adjacent (#1100), is still incomplete & requires proper lookup ?
A quick search on avoiding race conditions, says that the critical section of a resource sharing has to be atomical, as well as proper thread synchronisation.
Updated by Soren Stoutner 11 months ago
That's possible, although it could also be that the bug has existed for a while and nobody noticed or that it was introduced by some other recent change different from the opening of tabs adjacently.
Most likely it relates to all the problems in switching from ViewPager to ViewPager2 in Privacy Browser 3.14 with Feature #587: Switch FragmentPagerAdapters to FragmentStateAdapters. ViewPager2 is much more asynchronous than the previous implementation, which has ended up introducing dozens of bugs into the project (most of which I fixed in my testing before they were ever released to the public). As almost all of them are race conditions (which is what you get when you make things asynchronous), finding and squashing them all has been rather difficult. For example, Feature #1051: The first page is sometimes displayed if the app is restarted while a new intent is being loaded, Bug #1020: Unencrypted Website dialog sometimes erroneously pops up, and Bug #1069: App crashes after it has been paused and restored are all examples of race conditions introduced by ViewPager2 not always finishing creating new pages when they are expected by the rest of the app.
Updated by Soren Stoutner 11 months ago
@Lasse Gismo, can you please test this alt build of Privacy Browser to see if it resolves the problem for you? You can install it alongside your existing Privacy Browser. The link below will expire in about a week.
Updated by Soren Stoutner 11 months ago
The version in the above link has installation problems. Try this one:
Updated by Soren Stoutner 11 months ago
I have sometimes had to use a potential change for 2-4 weeks to be sure that a race condition is fixed. You can export your settings from your main Privacy Browser into this test version and use it for a while to see if you have any problems.
Updated by Lasse Gismo 11 months ago
A parallel installation of the test version in addition to my main PB is unproblematic?
Updated by Soren Stoutner 11 months ago
Yes. I designed the test version so it can be installed alongside the normal version without any problem. You will have two icons, one with the word TEST across the bottom.
Updated by ask low 11 months ago
Soren Stoutner wrote in #note-16:
Yes. I designed the test version so it can be installed alongside the normal version without any problem. You will have two icons, one with the word TEST across the bottom.
I would rather call it beta version instead of test version, since you're trying the changes that move into the standard version.
Not just this, but you can experiment a lot of other stuff. If you felt some feature stable & polished move that into standard version. If not, keep it experimental until it matures.
Which is why I suggested you to open a beta channel & release beta version (on redmine caz fdroid would take lot of time)
Updated by Soren Stoutner 11 months ago
There is actually an official test version that is part of every release, listed as the Alt version. It makes it easy to compare two releases side-by-side or do things like test import/export conversions between two particular versions. You can download them from:
https://www.stoutner.com/privacy-browser-android/changelog/
I might someday do a beta version, which is different from the Alt (test) version. But that is a different discussion.
Updated by Lasse Gismo 11 months ago
Not yet able to reproduce the issue with the alt build - looks promissing.
Updated by ask low 11 months ago
@Lasse Gismo Your issue could be different to mine. But happened on mine
https://redmine.stoutner.com/issues/1134#note-10
Updated by Soren Stoutner 11 months ago
That is interesting. I was expecting the change I made to fix Bug #1134: Sometimes the tab after a new tab in the middle of a list is set as active, but I wasn't sure it would fix this. Looks like it was the reverse of what I expected.
Updated by Lasse Gismo 11 months ago
- File Privacy Browser Android 3.16 Logcat09_07_24122023.txt Privacy Browser Android 3.16 Logcat09_07_24122023.txt added
Had the issue once again short before the timestamp (name) of the log attached.
Mostly open links out of the Fedilab app.
Seems to be, nearly, fixed from my point of view.
Updated by Soren Stoutner 11 months ago
Try this updated build. It has an additional change that might make the difference.
Updated by Lasse Gismo 11 months ago
- File Privacy Browser Android 3.16 Logcat 27122023.txt Privacy Browser Android 3.16 Logcat 27122023.txt added
The new build disimprove the behavior.
Installed YD, had 3 occurrences meanwhile.
Updated by Soren Stoutner 11 months ago
I can't imagine any way it would make things worse. Rather, it probably has to do with the variableness of the symptoms. The increase in the behavior is much more likely to be affected by whatever is happening on your device in the background. That is often the way race conditions are.
Updated by Soren Stoutner 11 months ago
Is there some way you could record a video of the crash? I realize this is problematic for crashes that don't occur consistently, but it might be helpful in determining what the underlying cause is.
Updated by Soren Stoutner 11 months ago
https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=83a2b6e5635956bb940642e0e5beb47453145dc3;ds=sidebyside makes some attempts at progress on this issue, although problems remain.
Updated by Lasse Gismo 11 months ago
There's no video required - its only a new tab with empty content and to close the tab, is to close the app.
Updated by Lasse Gismo 11 months ago
- File Screenshot_20231229-165734_Privacy Browser.png Screenshot_20231229-165734_Privacy Browser.png added
An additional, hopefully helpful, picture that shows 1 old and the new tab.
Tabbing on the new tab, shows information from the old and closing the new via X closes the app.
Updated by Soren Stoutner 11 months ago
- Subject changed from Opening a link in a new tab opens empty page, which crashes when closed to Sometimes a new tab is created without a corresponding new page
This is an interesting piece of information. It looks like a new tab is being created but a new page is not.
What is the procedure you are using to create the new tab?
Updated by Soren Stoutner 11 months ago
1. Does this ever happen when loading a link from inside the app? For example, if you long-press on a link and choose Open in New Tab. Or, if you use the + icon to open a new tab.
2. When this does happen when loading a link from Fedilab, is Privacy Browser recreated on load? You can tell if this is happening because the Privacy Browser logo will temporarily display on the screen. For context, you can check out the Android Activity Lifecycle:
https://developer.android.com/guide/components/activities/activity-lifecycle
If this is the case, you can force this to happen whenever you want for testing purposes by opening Privacy Browser, then opening 10-20 other apps (enough to force the OS to kill Privacy Browser to recover RAM), then opening a link from Fedilab.
3. Please post a copy of About > Version from inside Privacy Browser.
Updated by ask low 11 months ago
I believe there have to be some debugging tools for issues like these. As you said race conditions are very common. But whether handling is difficult or not I donno caz I ain't a dev.
But I've heard one can literally code an entire project with just try catch clauses is that true ?
Updated by Lasse Gismo 11 months ago
My answers:
1.) As I said - via link click in fedilab
2.) Didn't occur when PB is started with the click - only when there're already tab(s) open
3.) Pls. see attached
Updated by Soren Stoutner 11 months ago
Number 2 is very important. Let me explain further.
Android is constantly killing apps in the background. It does this for power saving issues, and to recover RAM needed by other apps, and sometimes for no good reason. Please see the attached graphic taken from Google's documentation.
Whenever an app leaves the screen, it is stopped and restarted. That is the portion of the graphic on the right. But, when an app is killed, then it has to be recreated when the user switches back to it. That is the process on the left of the graphic. This is all supposed to happen transparently to the user. Often they don't realize that their apps are constantly being killed and recreated. Developers, on the other hand, need to do a massive amount of work to recreate all the tabs, content, and other aspects of the app in the same state it was in before it was killed.
I suspect that this problem is only manifesting for you when Privacy Browser is killed in the background and then restarted by an intent sent from another app (Fedilab). Being able to confirm if that is the case or not is very important to being able to figure out the root cause and find a solution. The way you can tell if that is happening is that Privacy Browser has to reload the filterlists if it has been killed and restarted, which you can watch happen because the Privacy Browser logo will be displayed in the middle of the screen and the names of each of the filterlists will very briefly be displayed below it (similar to what happens when starting Privacy Browser from scratch, but in this case all the previous tabs will be restored after this step). This does not happen when the app is only stopped and restarted.
If this is the case, you can reliably recreate the behavior following the steps in #note-32. That makes it easy to test proposed solutions. If it is not the case, or if it is not consistent, then it makes things a bit more difficult.
Updated by Lasse Gismo 11 months ago
Ok - will take care of.
But - issue only happens when there're already tabs shown, after app kill (with super freezZ) and link click there's only the new one shown and that worked/s correct.
So - not sure what to do further.
Updated by Soren Stoutner 11 months ago
What happens if you have the OS kill the app in the background? This is different from what SuperFreezZ does (the onDestroy
at the bottom of the previous graphic), because when the OS does it the saved instance state is preserved, while when SuperFreezZ does it the saved instance state is deleted. You can test this by opening Privacy Browser, then opening 20-30 other apps, then opening a link from Fedilab. You will know that you have reproduced the app kill behavior because Privacy Browser will briefly display the app logo in the center of the screen with the loading filterlists text. Then you will see all the tabs restored, and the new tab created, although my guess is that in your case the new tab is not created correctly, which is why it displays the content from the previous tab and why it ends up causing the crash when you try to close it.
Figuring out if this is what happens is very important to getting to the bottom of the problem, because the code path for opening a new tab when recreating the app after it is killed is different than the code path for opening a new tab otherwise. Figuring out which case is causing your problem leads to looking in the right place to find the fix.
If I were able to reproduce this behavior on my devices it would be easier for me to troubleshoot. But this appears to be something fairly specific to the hardware and OS you have running. So, the more information I can get from you as to what exact circumstances trigger the problem, the more likely it is that I can find a solution. This differentiating of which code path is the problem is the first important step toward narrowing this down.
Updated by Lasse Gismo 11 months ago
OK, will stop walking my own way and follow yours - cmome back with results.
Updated by Lasse Gismo 11 months ago
- File Privacy Browser Android 3.16 Logcat09_07_24122023.txt Privacy Browser Android 3.16 Logcat09_07_24122023.txt added
Yep - did it your way with the behavior as expected.
PB killed via OS, link clicked, PB restored with earlier tabs and new tab empty.
The only inrofmationthe be seen, is the certificate info of the new page (mouse over tab)
Log attached with timestamp - good luck.
Updated by Soren Stoutner 11 months ago
This is good because it provides us a method to test prospective fixes. It is also good because it allows me to focus my hunt for the problem. I will look into it and get back with a test build once I think I have found a solution.
Updated by Soren Stoutner 11 months ago
- File Soren Privacy Browser Android 3.16 Logcat.txt Soren Privacy Browser Android 3.16 Logcat.txt added
I have encountered this problem for the first time on one of my devices. Attached is a logcat.
[ 01-03 15:49:52.622 7081: 7081 E/AndroidRuntime ] FATAL EXCEPTION: main Process: com.stoutner.privacybrowser.standard, PID: 7081 java.lang.IllegalStateException: Could not execute method for android:onClick at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:473) at android.view.View.performClick(View.java:7659) at android.view.View.performClickInternal(View.java:7636) at android.view.View.-$$Nest$mperformClickInternal(Unknown Source:0) at android.view.View$PerformClick.run(View.java:30156) at android.os.Handler.handleCallback(Handler.java:958) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:294) at android.app.ActivityThread.main(ActivityThread.java:8177) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Method.invoke(Native Method) at androidx.appcompat.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:468) ... 12 more Caused by: java.lang.NullPointerException: null cannot be cast to non-null type android.widget.FrameLayout at com.stoutner.privacybrowser.adapters.WebViewStateAdapter.deletePage(WebViewStateAdapter.kt:98) at com.stoutner.privacybrowser.activities.MainWebViewActivity.closeTab(MainWebViewActivity.kt:4074) ... 14 more
Interestingly, this comes after these lines, which are Bug #1106: New intents sometimes aren't loaded on restart on Android 14 (WebView crash):
[ 01-03 15:49:18.423 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=4805 bindings:W S [ 01-03 15:49:18.455 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=9271 bindings:W S [ 01-03 15:49:18.519 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=22844 bindings:W S [ 01-03 15:49:18.534 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=22650 bindings:W S [ 01-03 15:49:18.551 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=22647 bindings:W S [ 01-03 15:49:18.568 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=22631 bindings:W S [ 01-03 15:49:18.629 22476:22535 W/cr_ChildProcessConn ] onServiceDisconnected (crash or killed by oom): pid=22679 bindings:W S [ 01-03 15:49:18.657 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (4805) crash detected (code -1). [ 01-03 15:49:18.668 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (9271) crash detected (code -1). [ 01-03 15:49:18.687 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (22844) crash detected (code -1). [ 01-03 15:49:18.710 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (22650) crash detected (code -1). [ 01-03 15:49:18.716 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (5311) crash detected (code -1). [ 01-03 15:49:18.723 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (22647) crash detected (code -1). [ 01-03 15:49:18.739 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (4795) crash detected (code -1). [ 01-03 15:49:18.747 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (4869) crash detected (code -1). [ 01-03 15:49:18.753 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (22631) crash detected (code -1). [ 01-03 15:49:18.759 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(154)] Renderer process (22679) crash detected (code -1). [ 01-03 15:49:18.764 22476:22476 E/chromium ] [ERROR:aw_browser_terminator.cc(110)] Render process (4805) kill (OOM or update) wasn't handed by all associated webviews, killing application.
For me, I only see Bug #1106: New intents sometimes aren't loaded on restart on Android 14 (WebView crash) on Android 14, which is why it is missing from the logcats submitted by @Lasse Gismo. But it has a similar effect in that it causes the app to be recreated and the tabs to be restored. In this once instance that then caused this bug, which is that the number of tabs ends up being one more than the number of pages.
Updated by Soren Stoutner 11 months ago
@Lasse Gismo, can you try this test build and see if it resolves the problem for you? As usual, the link will expire in a few weeks.
Updated by Lasse Gismo 11 months ago
Looks good until now.
Will come back in a few days with results.
Updated by ask low 11 months ago
- File tabs_hang.log.txt tabs_hang.log.txt added
This test build has a severe issue of tabs hanging in the middle of nowhere
Updated by Soren Stoutner 11 months ago
I don't understand what you are describing. Can you please be a little more explicit?
Updated by Soren Stoutner 11 months ago
I can't see any way that any of the changes in this test version could cause that type of behavior. Rather, I would imagine it has something to do with Android System WebView itself and either an incompatibility with the website you are visiting or with one of the changes you are making as root where you are redirecting directories to /dev/null.
For example, your logcat has a lot of these:
[ 01-11 06:55:47.438 32491:32491 I/auditd ] type=1400 audit(0.0:108921): avc: denied { read } for comm="ThreadPoolForeg" name=48545450204361636865 dev="dm-4" ino=36658 scontext=u:r:untrusted_app:s0:c156,c256,c512,c768 tcontext=u:object_r:app_data_file:s0 tclass=lnk_file permissive=0 app=com.stoutner.privacybrowser.alt
And a lot of these:
[ 01-11 09:20:01.054 10056:10085 W/chromium ] [WARNING:cache_util.cc(144)] Unable to delete cache folder.
Updated by ask low 11 months ago
That's strange. I've symlinked /data/data/com.stoutner.privacybrowser.alt/\
to
cache/WebView/Default/HTTP\ Cache/dev/null
like how standard version used to be. The recent test build #1136#note-42 has hang issues, but strangely don't have this issue on #1134#note-12 build.
Updated by Soren Stoutner 11 months ago
Whatever is causing the problem, I can't imagine any way it relates to the changes in the code between those two versions.
Updated by Soren Stoutner 10 months ago
@ask low, if you have made any changes to WebView DevTools recently, you might try undoing them temporarily to see if they are responsible for the behavior you are seeing.
Updated by ask low 10 months ago
I actually had that issue & reverted back to my last alt build, even before I messed with DevTools.
You can see my comment timings of tabs hang log & your comment of DevTools recommendation. There's an hour difference.
Infact, I'm on the alt build from #1134#note-12 with the 4 flags enabled in DevTools. Browsed for almost 4 more hours without any hangs.
Updated by Soren Stoutner 10 months ago
I have committed the test build in #note-42 as it is likely to make progress even if it isn't the full fix. https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=commitdiff;h=70da2a558d6e35c38adb596479c36f7e451dc9a5;ds=sidebyside
However, I will leave this open until we hear back from @Lasse Gismo if this completely resolves his problem.
Updated by Lasse Gismo 10 months ago
After 2 weeks of working with, I'll declare the described bug as fixed with that release - congrats to Soren and many thanks.
Updated by Soren Stoutner 10 months ago
- Status changed from Feedback to Closed
Thanks for the followup information.