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

Termux is randomly closing / loosing sessions #122

Closed
Neo-Oli opened this issue Jul 31, 2016 · 27 comments
Closed

Termux is randomly closing / loosing sessions #122

Neo-Oli opened this issue Jul 31, 2016 · 27 comments

Comments

@Neo-Oli
Copy link
Member

Neo-Oli commented Jul 31, 2016

Hi, this has been talked about on #termux quite a bit, a while ago. But I'm opening an issue here, because it still affects me (on 3 different phones) and so it doesn't get forgotten and because it is quite severe.

On my phones, Termux would randomly close. This happens mostly in the middle of the night (on 2 out of 3 nights), but it has also happened multiple times while I was working with it over SSH.

Possible causes

FolderSync

At night my phone is running a few FolderSync tasks. There aren't a lot of files to be synced, but it does check a lot of files. I've checked and FolderSync isn't using up Memory or CPU.

Jekyll

In the cases of it closing while I'm working with it, it has happened noticably more frequent when working with Jekyll, while Jekyll is generating the website.

Speculation

It seems to happen during times of high filesystem activity. Is it maybe related to a filesystem interrupt? Like a file that needs to be read by the app which it can't do because the filesystem is overloaded?

All this happens with or without Wakelock held. Termux isn't entirely closing, it just seems to loose the session. The following screenshot shows "0 terminal sessions" and the Wakelock isn't held. As far as I know, Termux should only show 0 Sessions when a Wakelock is held.
screenshot_20160731-090626

I also once made termux do a continous logcat until it closed. https://gist.github.com/Neo-Oli/faa32ecb939c1f88cbcd7748a8377600

So far, this has only happened on marhmallow phones. It first appeared the day after I upgraded from KitKat.

Sadly, I can't produce a reproducible test case that doesn't involve waiting for 12 hours. I'm hoping someone else has the same issue as me. I'd be willing to run any test builds or do any debugging I can.

@Neo-Oli
Copy link
Member Author

Neo-Oli commented Aug 15, 2016

This has now started to occasionally occur occasionally on my server termux (which houses my IRC client and an IRC bot) as well. This device didn't do anything special. No foldersync, no jekyll.

Sadly, I had to switch back to using an Ubuntu box as server for now. Termux was perfect for the job as small, personal, home server due to low energy use and no noise emission.
I have now observed this on 3 devices:
Sony Xperia Z
Sony Xperia Z3c
Sony Xperia X
(Coincidentally, have no non Sony Device at the moment)

The Xperia Z is still running Android 5, which is weird, because the problem has only started happening on my Z3C after the marshmallow upgrade.

@Neo-Oli
Copy link
Member Author

Neo-Oli commented Oct 28, 2016

I have some interesting new observations about this: It has been happening exactly the same time these past 4 days. It's always at 09:10 exactly. For 4 days now termux has closed at 09:10. Since it's connected to my PC I notice pretty quickly. My Phone is doing nothing special at this time. I am not using foldersync anymore. It's just plugged into my PC. So either this is caused by something that runs at the same time every day or is caused exactly 24 hours after Termux starts. This Problem is so weird and elusive.

@bokuno
Copy link

bokuno commented Apr 5, 2017

The same here that Termux runs quite well for several days, then suddenly quits. Android 7.1.

@Neo-Oli
Copy link
Member Author

Neo-Oli commented Apr 12, 2017

I haven't had this issue in a long time. I think it is just a simple Memory problem. I no longer use any syncing apps (doing it in termux now) and it doesn't really happen anymore.

But I have some sort of test case here:
If I run this (ridiculous) command (which calculates PI to scale places)
echo "scale=2147483647; 4*a(1)" | bc -l
one of three things happens after about 10 seconds

  1. The process gets killed after it kills all other Android processes (including the software keyboard)
  2. The session gets killed, leading to the 0 terminal sessions state
  3. Termux gets killed
    #3 happens mostly when Termux is in the background (like running the command over ssh).

I think my original problem was simple the Memory usage of FolderSync killing Termux. But is there anything that can be done that would result in high Memory usage commands like the above one (or an intensive Jekyll build) to always lead to state #1, killing the runaway process but not all of Termux? It's quite annoying if it kills a tmux session or crond (leading to me not receiving any emails).

If nothing can be done about #3 can #2 at least be solved. Termux should exit if it looses all sessions.
I have a Tasker profile that monitors the Termux Background Service and launches Termux if it detects Termux to be not running. So if #3 happens, Termux gets automatically restarted (relaunching my crond and continuing syncing and notifying me about emails)

@Tesfaye01
Copy link

Did you solve this yet?
I also have the same issue on my LG android 7.1, 1.5gb ram & armv7l cpu. I am quite a noob but I think this is a memory problem, It started happening after I installed many apps in termux or if I opened other apps and try to multitask but sometimes it loses session on its own.
I also tried
echo "scale=2147483647; 4*a(1)" | bc -l
And the output was
Runtime warning (func=a, adr=451): scale too large, set to 2147483647
Runtime warning (func=a, adr=471): scale too large, set to 2147483647
Fatal error: Out of memory for malloc.
I don't know if this helps reproduce the problem but When I try to install shellen with
pip3 install shellen
It lags on installing keystone-engine and termux loses the session. It happened like three times.

@Quasic
Copy link
Contributor

Quasic commented Jul 11, 2018

I don't have much of a problem on my 2gb ram LG Android 7 phone, but my 1gb ram LG Android 5 phone closes apps all the time now. If I want to be sure the session doesn't end, I can't multitask much at all. Apps just take more ram, now. Having extra internal storage seems to help, possibly with some kind of virtual memory...

@ticalc-travis
Copy link

ticalc-travis commented Nov 22, 2018

I'm seeing Termux randomly stop running on a Samsung SM-J727U (Android 8.1) as well, but so far I've only seen it happen when the phone is left alone to charge for some time. I haven't had it happen when running on battery and actively using the device, including running multiple apps at the same time, etc. I have no idea what the connection is. Disabling the system app power monitoring service and adding Termux to the whitelist makes no difference.

And what's odd is that when after this happens and I come back and restart Termux, it then often crashes when I try to open the extra keys view (Volume Up+Q)

@Quasic
Copy link
Contributor

Quasic commented Feb 20, 2019

I do rarely have termux close abruptly on the Android 7 device when left alone for a while, not including when the app updates. It happens to other apps too, though.

@ghost
Copy link

ghost commented Feb 20, 2019

@Quasic So you have exactly same behaviour as in #122 (comment) ?

Without knowing which signal is sent to the shell, it is not possible to know what happens. If sigkill is sent, then there problem with Android OS. Though, logcat (and ideally output of dmesg - if device is rooted) will be needed too.

PS. I never had this issue on all my devices.

@Quasic
Copy link
Contributor

Quasic commented Feb 20, 2019

That comment link doesn't seem to work for me for some reason, but it only happens very rarely for any app in particular, and sometimes may not happen at all for weeks, (unless I happen to clear it after it happens without checking the Activity.) I don't know if I'll be able to find the logcat entry without logging it all while charging, but I assume that because termux seems no more affected than other apps, it is a system thing. I just actually cleared termux from recent apps, and it restored where I left off when relaunched.

@ticalc-travis
Copy link

I'm not sure if my issue is exactly the same as the original described one, but in my case the only time I've seen Termux unexpectedly quit was when I left my device to charge fully; and this behavior is pretty consistent. I haven't been able to catch exactly when the quit happens, though. It's not immediately but seems to be either after some time of charging like an hour or two, or perhaps even around the time the battery reaches full.

I don't have a rooted device, but I do seem to be able to access logcat from ADB (but not dmesg). Maybe next time I'll try to see if any clues show up.

@ghost
Copy link

ghost commented Mar 31, 2019

Same problem with Sony Xperia M (not tested on others). Most of the day at work bettercap and records events in a sniffing file. Session falls occur at night. The phone is usually on charge. Your phone's settings like everyone else, syncing with google turned on.
UPD: Notice this is the third time that the terminal session is ended at the time of full charging of the battery. The session falls exactly when the notification of full battery charge appears in the shutter.

@bpsib
Copy link

bpsib commented May 31, 2019

I have the same problem on LineageOS 14.1 and the notification also disappears. It sometimes closes while my phone is charging overnight. I think it should at least automatically restart like Tasker does when killed. My SSH server would then restart without me having to reopen Termux manually.

@houcemlaw
Copy link

same problem on my Huwaei mate 10 lite (4gb ram).
Keep closing randomly while compiling my nodejs project in background. Should be an android control i guess or a battery saving kind of matter.
Haven't dig deep though. Just keeping it in foreground while executing heavy processes (compiling processes for instance) would solve the issue. This will prevent you from doing other stuff while comlpiling but it will do for the moment.
Yet any other solutions would be of a great help.

@houcemlaw
Copy link

Ok I've just figured it out.
Go to settings - battery - launch and find the app you don't want to be terminated then change to manual mode(ensure that "run in background" option is enabled).
Problem solved!

@h43z
Copy link

h43z commented Oct 17, 2019

@houcemlaw I had this setting with termux and it still was stopped/killed.

@ticalc-travis
Copy link

ticalc-travis commented Oct 23, 2019

So I've finally noticed an interesting pattern to this in my particular case (Termux runs fine unless left on charge for a while, then it mysteriously stops, and it has nothing to do with battery-saving functions in the OS): It seems to be related to Android's/Google's device backup feature. I tried disabling the cloud backups in Google settings completely, and the next two times I left the device charging, Termux kept running without a problem when it would have definitely stopped. Then I turned the backups back on and waited a day or two, and sure enough, it went back to dying.

So I get a strong impression that Termux is dying for some reason when the Google backup service attempts to back the app up. Other apps don't seem to have this issue.

Since people here seem to be reporting symptoms that may have different causes, should I post a separate issue for this particular case?

@ghost
Copy link

ghost commented Oct 23, 2019

@ticalc-travis Termux has enabled support for Google backup. However, I'm not sure whether it is properly configured.

In https://github.com/termux/termux-app/blob/master/app/src/main/res/xml/backupscheme.xml we have:

<include domain="file" path="home/backup" />

which means to backup /data/data/com.termux/files/home/backup. That folder does not exist.
Maybe some error happens when Google services try to backup Termux data.

Probably better to use backup path path="home" but I'm not sure if backup feature will be useful -
documentation tells that amount of data limited to 25 MB while home folder can be much bigger. If we shouldn't disable this feature, then backup scheme should be more strict such as backing up only config files in common locations.

@ghost
Copy link

ghost commented Oct 24, 2019

Looks like Termux really gets killed when Google backup is working. Just reproduced it with starting manual backup in device settings.


Google backup doesn't work reliably. It backed up folder ~/backup with some files (as expected by app config) but after that it started to ignore any file updates.

Better to disable this feature and Termux will no longer be stopped when it is running.

@hardikhari96
Copy link

May Be phone system trying to close background process of termux , i face same problem in my phone its close connection after certain period of time.

@ghost
Copy link

ghost commented Apr 28, 2020

This damn issue is still happening for no reason.

Recently I started using termux on a HUAWEI P9 Lite which has android 7, before using termux on that phone I was using a android 5.1, and it worked fine. Then termux started from no where to close which annoyed me.

I am running a discord bot on this phone which makes it harder to make it 24/7. I tried disabling backups by Google services, and I monitored my phone hours, and when I went to sleep, after half an hour or more, it stopped randomly.. When I discovered this I was beyond annoyed anymore. I just ran it one more time before going to sleep. Today again I found out that termux closed again. Any any ANY ideas?

@termux termux deleted a comment from mus1415 Apr 28, 2020
@Grimler91
Copy link
Member

@Cristy86 Probably a battery saving or high memory usage protection feature.
Try disabling all such features.

A logcat would help to see more precisely why termux is killed. You can run logcat -f /sdcard/logcat -r 16 in another session and then check the content of /sdcard/logcat after a crash to see what happens.
You might have to run it as root or in an adb shell to capture all the information.

It is probably a huawei specific issue: #1172

@ghost
Copy link

ghost commented Apr 28, 2020

Right. I disabled some of the battery saving features and I will see if that's the case.

@ghost

This comment has been minimized.

@NFC-Playplace
Copy link

... My termux shuts down after 5min after i background it, or as soon as i start using something that it's running while in the background(for example visiting a website that it's hosting) and it's fine as long as i'm on the app but really annoying when i'm not. also it's on a android 9 phone

@Quasic
Copy link
Contributor

Quasic commented Nov 4, 2020

The Android 5 phone that used to close it all the time now keeps the sessions very well. The only thing I really changed was taking it off of cell service. I assume it freed enough RAM to let more apps run at the same time.

@hjudt
Copy link

hjudt commented Jul 14, 2021

You can try my workaround described here #1172 (comment) and see whether it works for your device (I had to apply the workaround for huawei mate9 with that default emui stuff on it).

@ghost ghost locked and limited conversation to collaborators Oct 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests