Closed axet closed 6 years ago
Seems to be a duplicate of #634. Ping @capi.
I noticed it as well on my device recently. WiFi was detected properly according to adb log
but subprocess was not started. I have not yet been able to reproduce it and track it down. I'm on it. Unfortunately I'm quite busy at the moment and I have little time to do development, sorry. I think, a sensible approach is to tackle #729 first, so that we get better information why Syncthing is stopped.
@Nutomic we might have been looking at this too narrowly with WiFi. I had the issue yesterday twice when unplugging the device from A/C. The notification stayed active, clicking on it launched Syncthing in the above state. Only way to get it working again, was to re-plugin to power (then it really started) and then unplugging (and stopping in my case) worked as expected.
Unfortunately the logcat application doesn't work on my phone and until I reached a PC with adb, the log was long gone. But it's interesting to see this behaviour not only related to WiFi but also to A/C-only.
Unfortunately the logcat application doesn't work on my phone a
umm, Termux, su, logcat -v threadtime > /sdcard/log1.txt
wait a bit and ^C (VOLUME UP+C) ;)
@licaon-kter that would require a rooted phone :)
Might I suggest changing the issue subject to something more specific? I came here for this exact problem, this issue was the most recent, and it was exactly what I was looking for, but I would have never guessed it from the title.
I don't know if this helps, but I've noticed on my phone (Nexus 6P running stock Android 7.0) that this happens whenever I leave range of a wireless network then come back into range without connecting to any other network (For example, if I go far enough down the street from my house that I am no longer connected to my home WiFi network, then go back, all without connecting to any other WiFi network).
I can usually get things working again by toggling WiFi on and off again, which is tedious, but works a s a short term workaround.
I've never seen the issue when disconnecting from a charger though.
@Ferroin Thanks, its something to investigate towards. Once we have some reproducibility, I'm quite sure it can be solved.
Well, for what it's worth, I see this at least once a day on work-days when I take a walk around the block at lunch. While I obviously can't help with the charging related aspect, I'll be happy to help with testing fixes for the WiFi side of things (including side-loading development builds if needed).
For what it's worth, I encountered this problem even if my Wifi stayed on. I just find that the problem exist if I turn on built-in battery saver mode on my HTC E8 (I always turn it on for lower screen brightness and CPU usage). Is there any option to turn off this function (i.e. stop Syncthing from running when in battery saver mode)?
And I actually didn't think the battery saver mode is the cause of problem, until a read the release note in Github with this line: "respect battery saving mode and global sync setting". I hope there is clearer instruction when implementation such new functions.
I'm not sure if it is the right place or should it open it as a separate issue. Please advise.
@nigelinux Please open a separate issue for the "battery saver mode" change so that we don't mix the discussions.
OK, now that I'm actively paying attention, I'm noticing that while leaving WiFi reliably triggers it for me, it also happens pseudo-randomly. Just over the weekend, I've been trying to watch it whenever I can,. I've never seen when it actually happens, but it appears that the phone has to sleep, and Syncthing has to be idle (everything in sync, nothing being transferred.
On a hunch, I tried disabling Battery Optimization for Syncthing from the system settings (in stock Android 7.0, go to the Battery section of settings, hit the 3 dots in the top right and select battery optimization, then find Syncthing in the list and turn off Battery Optimization for it, note that this is not the same as Battery Saver mode), and that seems to help a bit, but not completely fix this.
@Ferroin Have you tried enabling "Run service with foreground priority" from the "Experimental" section?
@capi I'm not certain I've seen that anywhere in the settings, I'll double check and see if I can find it, and if so, I'll try that too.
Do check out: battery optimisation turns off global Synchronization when activated?
@licaon-kter Battery Saver mode does turn off global sync when enabled, but Battery Optimization is different from that, and shouldn't directly affect that.
Battery Optimization does a bunch of things on a per-app basis based on usage and other factors to try and reduce the application's battery usage without impacting it's usability. It does things like suspending apps which aren't in the foreground when the foreground component hasn't been used in a while, which is what I think is part of what is happening here.
@capi I haven't been able to find any option with a name like that anywhere in any of the settings on my phone (including in the Developer options and the System UI Tuner).
Umm, Syncthing respects global sync state, hence... battery optimisations stops sync which in turn stops Syncthing.
@licaon-kter Like I said, Battery Saver Mode is NOT the same as Battery Optimization, the two are two different things operating in different ways at different levels doing different things. Battery optimization is a normal runtime mechanism that does regular things that don't break any guarantees provided by the Android API. Battery Saver Mode (at least on stock Android) is intended to be a last ditch effort to keep the device operation at a minimal level when the battery is low (the default in 7.0 is to turn it on at 5% remaining charge). Syncthing should be essentially non-functional when Battery Saver Mode is on, but Battery optimization should not impact it to this degree. Given what Battery Optimization does, the only impact should be that it takes longer for Syncthing to see changes (either local or remote) when it's enabled.
@Ferroin It's a setting in Syncthing's "Experimental" section.
Ah, that would explain why I couldn't find it in the system settings...
FWIW, since turning off Battery Optimization for Syncthing, I've only seen this issue under the conditions I outlined above with leaving and reentering a WiFi network. Given that, I'll try with the foreground priority option on and Battery optimization enabled and see if that gets similar results. Based on what I know about Battery Optimization, I think that should have the net result of making it think the app is constantly in use.
OK, just preliminary results, but it looks like setting Syncthing to run the service with foreground priority is helping to the same degree as disabling Battery Optimization for Syncthing. It appears to at least reduce the random issue, but not the issue I see when leaving range of a WiFi network then reentering range. Of course, this is just on my system, so it would be great if someone else could check as well.
OK, further update, running the service with foreground priority doesn't seem to help much by itself, as it had no noticeable impact. So far based on what I've tried, disabling Battery Optimization for Syncthing seems to be the most reliable fix for me, but I still have the issues with it getting into a disabled state when I leave range of WiFi. If anyone else has any further suggestions, I'll be happy to help test them.
I've had the same problem. The issue seems to be that it will give this error message correctly the first time due to a trigger (such as WiFi being off, etc.), but the user needs to soft-close the app (swiping away the task in the Recent Tasks view) and re-open once the app is connected to WiFi, etc. Basically, the "warning" message the app gives the user doesn't clear until the user clears it his or herself, either by soft-closing the app or clicking "change settings" (albeit may not even be changing settings).
OK, this is odd, I haven't seen this issue any more since I reset my phone to enable file-level encryption right around the same time that I got the update to 0.8.4 for syncthing-android. I've still got things set so battery-optimization is disabled for Syncthing, and it's not running the service in the foreground.
I've now only seen this once since I last posted about it, and I was able to trace that one time to being on a WiFi network that didn't actually have an internet connection then switching to one that did. I'm not sure if this is fixed for anyone else, but it seems to be working correctly for me now.
Hmm, at the moment we are listening for CONNECTIVITY_ACTION
. According to http://stackoverflow.com/a/5890104, it could also be required to listen for android.net.wifi.STATE_CHANGE
.
OK, more data. If I connect my phone to a network through a USB Ethernet adapter, and then disconnect from that network, Syncthing will afterwards constantly claim to be disabled regardless of the state of WiFi, and toggling WiFi or the 'Only Sync on WiFi' setting don't help (I'm checking now if a full reboot of the phone fixes things).
I'm using this tricks in my app (Wifi only option)
Considering the aspect of WiFi networks without an internet connection, could you please check if the app can be notified also when reaching that connection state?
I have a laptop connected to a WiFi router with no internet uplink. When I take my phone there, it would be nice if syncthing was activated and synced with the laptop. The mesh network nature of syncthing is ideal for this kind of direct client connection without access to any central server.
But currently the app stays disabled because Android regards the WiFi as "broken".
Thanks for the hint, had not seen that issue. I thought maybe since the changes on Android 7 require a code change anyway, this could have changed in the meantime.
Hmm, at the moment we are listening for CONNECTIVITY_ACTION. According to http://stackoverflow.com/a/5890104, it could also be required to listen for android.net.wifi.STATE_CHANGE.
No clue about Android APIs, but that sounds like it might give more detailed information about the WiFi state?
AFAIK, if the WIfi has no internet and you have a working cell data connection, you cannot ever connect to devices on the Wifi. I tried to access the admin interface of the router to activate internet by using the internal ip, but every browser on Android told me, that it couldn't connect.
So even if Syncthing was running, all traffic would still go through cell data.
To connect to a Wifi without internet, you have to disable cell data in the Android settings. Then Android will tell Syncthing that it has a Wifi connection.
AFAIUI based on what I've seen from other apps, it's if you can't get an IP that you can't talk on WiFi. I do know it behaves differently with a captive portal versus not being able to determine an upstream router though, so that may have something to do with it.
FWIW I've been getting this behaviour for a couple of months now. Nexus4 CM13 (Android 6.0.1), ST-Android 0.8.8, ST 0.14.9.
Never turn WiFi off, use case is leaving home WiFi, connecting to work WiFi, then back to home at the end of the day. Only plugged in overnight for charging. Options are to run in background, sync on wifi and use advanced folder picker. No WiFi network restrictions, no metering on WiFi (but metered OTA). Only by disabling sync on wifi does it start working.
I still get this with 0.9.0 on Lolipop. The wifi is on and when I enable only sync on wifi, it wants me to change the settings refuses to run properly. Nagging me about syncthing being disabled with a pop up.
Not only that but disabling the wifi only is not enough, it stills nags about it. I have to disable the sync only when charging option to get it running.
This apps get weirder and weirder by day, sorry to say this.
I just wished that the run in background is not ttied to the wifi and the charging options. They should be separate things.I want to run syncthing only when charging but I do not want to run it in the bg at all times at all.
I still have this issue with 0.9.2
thanks
It's being caused by the Doze feature built into Android, which will only get worse in Nougat for the common user that may not know why these problems are being triggered. Luckily I've noticed in the past weeks that ST has added a warning screen mentioning the user to remove Syncthing from the list of optimized apps with simple and quick instructions to go along.
@Axet, what type of device are you running this on? Samsung? HTC? Sony? I haven't had time to go through the details
@jebeld17 lg nexus 5
FWIW, disabling Battery Optimization (the official name for the Doze feature as connected to apps) makes it work about 99% of the time for me on Android 7.0+ (I've tested every version from 7.0 to 7.1.1) on my Nexus 6P. There are still a few corner cases where Syncthing gets confused:
I've been using the app with the experimental Foreground Priority for about a week and I think it solved it for me.
I've seen pretty much the same results doing that, but using Foreground Priority instead of disabling Battery Optimization actually drains my battery faster, hence my preference to disable Battery Optimization for Syncthing.
Every device is different and every manufacturer applies their own rules, etc. on top of what Google already has, so my issue I had was caused by HTC's Boost+ app built into the Android with Sense OS itself for HTC devices. Just removing Syncthing from the Doze feature doesn't cut it for me because there is an entirely different app doing what Android is already doing on it's own terms running simultaneously.
I assume you do not have any "app-killing" apps running in the background constantly, correct?
No, the only things I have running in the background beyond the stock Android stuff (Google Play Services, Now Launcher, etc) are Syncthing and BOINC (which only actually does anything when the phone is on a charger and at 90%+ charge). The Nexus 6P is also true stock Android (with a small amount of work, it's actually possible to run AOSP on it), so I'm lucky enough not to have to deal with vendor bloatware getting in the way.
TBH, there's not really much that Syncthing can do regarding crap like Boost+ other than telling people it is known to cause issues (and may be causing issues with other stuff they have on their phone too).
BOINC could be causing the Syncthing process to end abruptly. Reason why is because BOINC is very heavy on system resources (given the right conditions), and if you do not have many files and computing power Syncthing needs to access from Android, Android could be killing the Syncthing process anyways in order to give more room and processing power to BOINC that is in the highest demand.
I would recommend bringing your processing requirements for BOINC down by half and seeing how Syncthing responds to that.
I already disabled the battery optimization and I still got the problem.
@gerroon @Ferroin that doesn't necessarily mean Syncthing will stay active. The nature of the OS is to kill off the less needed background tasks to make room for more energy consuming tasks, such as BOINC. If your phone begins to run out of resources, Android will always begin to do this just by nature of design.
I never have this issue when at home with the phone on a charger, which is the only time BOINC is actually doing anything other than sitting there in memory waiting for a notification that the phone got connected to a charger, so I'm pretty certain it's not BOINC. Also, given standard operation design of Android combined with how BOINC tags itself, BOINC will get killed first (I've actually tested this before) because it uses more memory than anything else on the phone and identifies as a low-priority task.
Like I said earlier though, the only cases I actually see issues now that Battery Optimization is off for Syncthing and I'm using Android 7.0+ are when doing odd networking things (USB Ethernet or acting as a Bluetooth NAP/DUN client), or on rare occasion under the conditions I used to see it (leave range of a Wi-Fi network, then re-enter range after more than about 5 minutes without connecting to another Wi-Fi network). In all cases, it's infrequent enough that it's just an annoyance, not something that makes Syncthing unusable. In the odd networking use cases, I've seen other apps which try to only run when a Wi-Fi connection is active freak-out and stop working as well, so I'm inclined to believe that it's just not an easy problem to solve.
@Ferroin Is there anything running - in the foreground or background - that may be eating up resources? This is disregarding Syncthing.
PS: Although BOINC may not be actually computing at the time when your phone is unplugged, BOINC is still allowed to hold processes in the RAM and cache. If BOINC has a higher priority in any way, shape, or form in Android over ST, Android will still kill off ST first if other apps begin to use up the remaining x% of RAM (and cache in some cases).
PS PS: I read your previous message over again, I now see that you have already tested how BOINC behaves with Android's built-in task killing ways while unplugged - But regardless, maybe BOINC is still being seen as a higher priority task over Syncthing?
Time-to-time syncthing shows disabled screen when I open app. Seems like it can't proper detect my Wifi connection. It been happening for a while (since beginning... a few months...)
App Version: 0.8.3
http://pastebin.com/n7C80d28