Catfriend1 / syncthing-android

Syncthing-Fork - A Syncthing Wrapper for Android.
Mozilla Public License 2.0
1.91k stars 57 forks source link

v1.3+/LOS16: Phones reboot when NAT traversal is enabled in "Syncthing Options" #505

Closed Catfriend1 closed 4 years ago

Catfriend1 commented 5 years ago

Taken from forum user post @kisenberg @shscs911: https://forum.syncthing.net/t/phones-reboot-with-syncthing-1-30-under-lineageos-16-on-htc-m8/13849

Quoted from PM;

Description of the issue

@kistenberg

I did a clear install of LineageOS 16 on an HTC m8 and Syncthing 1.2.2. Everythings run fine. Yesterday, Google Play Store updates Syncthing to 1.30. After few minutes later my phone reboots by itself. After it came up again and maybe 30 seconds later, the phone did reboot again. This happend until I managed to disable Syncthing. Also the phone got hot. (...) Clean install of LineageOS 16, several clean install of Syncthing 1.30 (also with cleared data and cache), also update from running 1.2.2 or clean install of Syncthing 1.3 with imported config; all the same behavior: both phones(!) reboot. No problem with 1.2.2. Was there a change in libraries or version of software components from 1.2.2 to 1.30? I’m clueless.

It’s a great work from the maintainer. I love the tool. It would be a pain not to use it anymore.

I have another HTC m8 to install and did also a clear install of LineageOs 16. I also installed Syncthing 1.30 from Play Store. A few seconds after starting Syncthing and granted all necessary rights, Syncthing began to create its key and the phone rebooted by itself.

Maybe with release of version 1.30, there seems to be somethong wrong. Two working and clean installed phones get in boot loop after Syncthing 1.3 was installed. Version 1.2.2 works fine on it.

@shscs911

I am having the same issue on my OnePlus One running custom DirtyUnicorns 12 ROM based on Android Oreo. Opening the Syncthing app reboots the phone to bootlogo. I can confirm that it was working well before the last update. Is it somehow related to this: https://github.com/syncthing/syncthing-android/issues/1001 8 ? Unfortunately I don’t have access to my phone now. Will post the logs as soon as I get my phone back.

Version Information

App Version: 1.3.0.x
Syncthing Version: v1.3.0
Android Version:  LineAgeOS 16, DiryUnicorns 12
Device manufacturer: HTC, Oneplus
Device model: HTC m8, OnePlus One

Android Log

adb shell / logcat
or MatLog (search on GitHub) output
Catfriend1 commented 5 years ago

@shscs911 Ok, could you please run syncthing (in green status) with:

Catfriend1 commented 5 years ago

Quote from @shscs911

Global Local NAT Traversing Relay Reboot
:heavy_check_mark:  x x x No
:heavy_check_mark:  x :heavy_check_mark:  x Yes
x x :heavy_check_mark:  x Yes
x :heavy_check_mark:  x x No

(...) I think NAT’s causing problems.

Catfriend1 commented 5 years ago

For my consideration:

Quote from https://en.wikipedia.org/wiki/NAT_traversal

Symmetric NAT The recent proliferation of symmetric NATs has reduced NAT traversal success rates in many practical situations, such as for mobile and public WiFi connections. Hole punching techniques, such as STUN and ICE, fail in traversing symmetric NATs without the help of a relay server, as is practiced in TURN. Techniques that traverse symmetric NATs by attempting to predict the next port to be opened by each NAT device were discovered in 2003 by Yutaka Takeda at Panasonic Communications Research Laboratory[4] and in 2008 by researchers at Waseda University.[5] Port prediction techniques are only effective with NAT devices that use known deterministic algorithms for port selection. This predictable yet non-static port allocation scheme is uncommon in large scale NATs such as those used in 4G LTE networks and therefore port prediction is largely ineffective on those mobile broadband networks.

Catfriend1 commented 5 years ago

Update from forum thread:

Catfriend1 commented 5 years ago

Todo: Disable "NAT Traversal" if kernel is 3.4.x @klausenbusk @kisenberg

Useful : http://www.devexchanges.info/2015/06/get-some-basic-android-device.html?m=1

Java.lang.System.getProperty("os.version")

klausenbusk commented 5 years ago

Todo: Disable "NAT Traversal" if kernel is 3.4.x @klausenbusk @kisenberg

See also: https://github.com/syncthing/syncthing-android/issues/1425

Catfriend1 commented 5 years ago

The fix will be part of an upcoming release.

Catfriend1 commented 5 years ago

Please see release: https://github.com/Catfriend1/syncthing-android/releases/tag/v1.3.0.2

Catfriend1 commented 4 years ago

So, I've installed LineAgeOs 16 2020-04-07 unofficial from xda to Samsung note n7000 and the app immediately causes a phone hot reboot when the native binary starts. The fix doesn't seem to detect the affected os. Will need to adjust it.

klausenbusk commented 4 years ago

So, I've installed LineAgeOs 16 2020-04-07 unofficial from xda to Samsung note n7000 and the app immediately causes a phone hot reboot when the native binary starts. The fix doesn't seem to detect the affected os. Will need to adjust it.

You should apply this patch if possible, it fixed the issue for me (Samsung S4 Mini 3.4.x).

Catfriend1 commented 4 years ago

Yes , I've found that link and reported it to the rom developer :+1 thanks.

funnyflowerpot commented 4 years ago

Hi @Catfriend1 thanks a lot for putting effort into this issue!

I would love to use Synthing on my old LineageOS phone, but it seems this issue is also a blocker for me. (That version of LineageOS is pretty dead, but so far everything runs fine for my humble needs.)

As described in this comment, I can also provoke a reboot with ip route get 8.8.8.8. My kernel is:

# uname -r
3.4.113-K^Kernel-OC-UV

I was happy to find Syncthing-Fork and this issue. However, I seem get the same results and "The fix doesn't seem to detect the affected os.", as you mention above. I tried provoking the problem while running the following command, but I did not get any output.

adb logcat -b events -b main -b radio -b system | grep "Disabling NAT"

Thanks again for putting energy into this! I would really like to get Synthing to work. Please let me know, if I can help somehow.

funnyflowerpot commented 4 years ago

I also tried adding this line

<boolean name="natEnabled" value="false" />

to the file

/data/data/com.github.catfriend1.syncthingandroid/shared_prefs/com.github.catfriend1.syncthingandroid_preferences.xml

but this also seems to have no effect. (I tried the same for the not-forked version of Syncthing with the same results.)

Maybe it is worth mentioning that the reboot is preceded by a freeze of a long time. The phone is not getting unexpectedly hot.

Catfriend1 commented 4 years ago

I'll see what can be done.. have got an old phone affected too those days but hadn't time and motivation to work on it yet. You can try disabling wifi so syncthing fork will not run the native. Then, try to export settings. Take config.xml and put nat to false. Go back and import your modified config. Connect wifi, it will work.

Catfriend1 commented 4 years ago

Ok, mine is:

Samsung Note N7000 - LOS 16 - 3.0.101-gf32669ee5be #1 Tue Apr 7 20:05:58 +08 2020

Catfriend1 commented 4 years ago

Fixed the log, it should now output the line "D/ConfigXml: Disabling NAT option because a buggy kernel was detected." when an affected kernel is detected.

Catfriend1 commented 4 years ago

Fix verified working on "Samsung Note N7000" which was affected and crashed before. It will be part of an upcoming release soon.

funnyflowerpot commented 4 years ago

Dear @Catfriend1, thank you for investing time into this issue and trying to support the people staying faithful to old, but functional hardware!

I installed the v1.6.0.1 preview-release which includes the above commit. I can confirm that I can see the line you mention in the log output now. However, this did not change anything unfortunately, as the phone crashed again. This is consistent with the results I got when following the instructions you stated in https://github.com/Catfriend1/syncthing-android/issues/505#issuecomment-625377066. I followed them thoroughly multiple times, but always ran into a crash and eventual reboot.

Somewhat desperately I went through the full log output on maximum verbosity to see what I could find. Please check lines 4 and 5 in the output below. I did not pay much attention to the subsequent warning, as Syncthing seemed to continue running (without network activity). However, I ran the attempted chmod command as root to prevent further attempts, cleared Syncthing's data, started the app and I did not run into a crash so far. Usually a crash happened after establishing a wireless network connection, which worked fine now.

Not sure why this happened or whether things work now, but I will experiment a little more and see whether I can use Syncthing now. It may seem now that my problem was/is not actually related to this issue. However, even if that chmod-problem would have been solved earlier, I would have probably run into this issue, as my LineageOS and kernel version fits the problem description.

Thank you very much in any case for your support!

D/Util    ( 2649): runShellCommandGetOutput: ps
I/Util    ( 2649): runShellCommandGetOutput: Exited with code 0
I/PollWebGuiAvailableTask( 2649): Starting to poll for web gui availability
D/Util    ( 2649): runShellCommand: chmod 500 /data/app-lib/com.github.catfriend1.syncthingandroid.debug-2/libsyncthingnative.so
W/SyncthingRunnable( 2649): chmod SyncthingNative failed with exit code 10
V/NotificationHandler( 2649): Starting foreground service or updating notification
I/notification_enqueue(  498): [com.github.catfriend1.syncthingandroid.debug,1,NULL,0,Notification(pri=-2 contentView=com.github.catfriend1.syncthingandroid.debug/0x1090065 vibrate=null sound=null defaults=0x0 flags=0x4a kind=[null])]
I/notification_cancel(  498): [com.github.catfriend1.syncthingandroid.debug,4,NULL,0,0,64]
funnyflowerpot commented 4 years ago

I looked for some hints in the issues for Syncthing-Fork and Syncthing and stumbled upon this issue. I observe that there the same chmod error appears in the log output. I assume that you refer to the same Samsung Note as you mention here above. However, with all other things being equal this would object my hypothesis that the chmod error caused my problem. Not sure what to do with that.

I should add that I described my problem as crash, but more precisely the phone freezes (ANR) for a while (Few minutes maybe? Did not count.) and eventually reboots.

Catfriend1 commented 4 years ago

Hi @funnyflowerpot and sorry but I'm currently seeking going to get some rest and haven't got much time as it's late... Could you please try upgrading to v1.6.0.2? (root and monitor process bug solved) If the native runs correctly, the chmod isn't crucial to operation. I wonder if the patch just kicks in fast enough on the initial setup with the key generation?! Will have a look those days but can't promise when exactly.

funnyflowerpot commented 4 years ago

Hi @Catfriend1, thank you again and sorry for the late response. I did some more testing, with v1.6.0.2 and in general. I came to believe that something is wrong with the ROM of LineageOS I use.

I had weird problems in the past and was reluctant to consider a common source. But after recent updates I encounter more problems related to HTTP/HTTPS communication in other apps, too. Regarding my problem above I have to suspect it is a problem of the ROM, not Syncthing, so I think it is better to let this issue rest, as it should.

Side note: I unearthed another second-hand phone and Syncthing seems to run on that non-standard Android 5, so I won't continue digging here either. Thanks again for your efforts!

Catfriend1 commented 4 years ago

Ok, thanks for your feedback much appreciated.