termux-api icon indicating copy to clipboard operation
termux-api copied to clipboard

termux-api commands hang in terminal without any output

Open johnwuelk opened this issue 2 years ago • 27 comments

Problem description

termux-api commands do not work and hang in terminal without any visible output. The only thing I can do is Control+c for cancelling the command. According to forum posts, I'm not the only encountering this issue.

Steps to reproduce

Newest version of termux-api and termux is installed from F-Droid and all permissions are granted in the app settings for both apps. Plus, battery optimization is turned off for all termux apps, so that termux apps are granted to run unlimited at all times. termux-battery-status is weirdly only working sometimes, it has only worked 2 or 3 times out of the many I tried. The other commands do not work at all. Rebooting and/or reinstalling the apps did not lead to any solution.

Expected behavior

Regular output of termux-api specific commands like termux-battery-status

Additional information The phones were NOT rooted. Does the Android device really have to be rooted for termux-api to (fully) work all the time?

  • Termux application version: 0.117 and termux-api version 0.56
  • Android OS version: 9 and 10
  • Device model: Blu G60 and Blu G90

johnwuelk avatar Nov 21 '21 02:11 johnwuelk

Do you have the termux-api app installed? You mention the installed version of the termux-api package, but not of the app.

Termux-api should work without root, trying to use it as root will in fact lead to issues

Grimler91 avatar Jan 02 '22 08:01 Grimler91

Yes, I have the termux-api APP from F-Droid installed as well, not only the package within termux.

It does work without root on other phones like Samsung but sadly not on my Blu phone.

johnwuelk avatar Jan 03 '22 06:01 johnwuelk

Do you get any errors/warnings/related output in adb logcat when trying to use it?

Grimler91 avatar Jan 03 '22 07:01 Grimler91

Yes:

~ $ adb logcat

* daemon not running; starting now at tcp:5037
* daemon started successfully
- waiting for device -

johnwuelk avatar Jan 04 '22 06:01 johnwuelk

Yes:

Generate a full dump after connecting phone to pc, running api command and then running command on pc: adb shell -d > logcat.txt

https://developer.android.com/studio/command-line/logcat

You should also disable battery optimizations and duraspeed, etc.

https://dontkillmyapp.com/

agnostic-apollo avatar Jan 04 '22 07:01 agnostic-apollo

adb shell logcat -d > logcat.txt worked and generated this following file: logcat.txt termux-battery-status was running on phone before I ran above command.

if this is relevant the output of termux-api-start was: Starting service: Intent { cmp=com.termux.api/.KeepAliveService }

Any battery optimization was disabled and no battery app installed.

johnwuelk avatar Jan 07 '22 00:01 johnwuelk

termux-api-start

I did not even have a clue about this command

And btw can you extend the expiration of action files? The latest and all previous have expired

john-peterson avatar Aug 20 '23 06:08 john-peterson

And btw can you extend the expiration of action files? The latest and all previous have expired

90 days is the max possible time for keeping GitHub Actions artifacts in public repositories.

sylirre avatar Aug 20 '23 07:08 sylirre

The latest and all previous have expired

https://github.com/termux/termux-api/actions/runs/5930893260

agnostic-apollo avatar Aug 21 '23 20:08 agnostic-apollo

Im in same position. Were any meaningful actions to take found? Even on another phone when *-api commands /did/ work, there was usually a 2-5 second delay, so I expected the wait...once it got over a minute I headed here to search.

Where do we go from here?

Here's strace termux-sms-list , maybe thats helpful? https://pastebin.com/hebAL3Ux

rocket-pig avatar Sep 07 '23 13:09 rocket-pig

Here's strace termux-sms-list , maybe thats helpful? https://pastebin.com/hebAL3Ux

Your log is not correct as basically traces shell execution. You need to include -f (--follow-forks) strace option to trace also termux-api server. But you won't be able to debug Termux:API application with strace.


Background:

termux-sms-list is a shell script that spawns termux-api server. The server itself sends an intent to Android OS to start Termux:API application and then creates sockets on which listens for connection from Termux:API.

If you don't have Termux:API Android application (Termux API consists of Termux:API application and termux-api package) installed, termux-sms-list will wait indefinitely. Same would happen if Termux:API was not able to start because the termux-api server will not exit until connection was received.

sylirre avatar Sep 07 '23 13:09 sylirre

Hi, I appreciate response - I have both installed and actually reinstalled both before posting just to double make sure. Still same result. I can try the -f hook if its helpful? (Is that what youre saying, or that it also wouldnt be?)

Edit: termux-api-start completes instantly with this output: "Starting service: Intent { cmp=com.termux.api/.KeepAliveService }"

rocket-pig avatar Sep 07 '23 13:09 rocket-pig

Try with -f, at least it should tell whether termux-api part was started properly.

sylirre avatar Sep 07 '23 14:09 sylirre

its 1.5MB of text, pastebin has no upload function and other sites are giving me grief as well. It ends with many many copies of the mprotect line... Im not knowlegable enough to decipher what this means or if its helpful in troubleshooting why this is happening for folks. Edit:andn amazing, the termux copy/paste and github's cr/lf /r/n 'carraiage return' apparently arent a match either. what a nightmare. github also says i can upload, then the file is greyed out in the selector. and now trying to add line ends to the texxt inserts tabs which...im not going to spend two hours trying to un-fuck this when its unclear if its even going to help smarter people troubleshoot.

[pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ) = 0
 [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ|PROT_WRITE) = 0                                                              [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ) = 0         [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ|PROT_WRITE) = 0                                                              [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ) = 0         [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ|PROT_WRITE) = 0                                                              [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ) = 0         [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ|PROT_WRITE) = 0                                                              [pid 13823] mprotect(0x79c43cd000, 4096, PROT_READ) = 0         [pid 13823] munmap(0x79c313e000, 4096)  = 0                     [pid 13823] munmap(0x79c3271000, 4096)  = 0                     [pid 13823] munmap(0x79c3274000, 4096)  = 0                     [pid 13823] munmap(0x79c43cc000, 4096)  = 0                     [pid 13823] munmap(0x79c43cd000, 4096)  = 0                     [pid 13823] exit_group(0 <unfinished ...>                       [pid 13834] <... futex resumed>)        = ? <unavailable>       [pid 13840] <... ioctl resumed>)        = ? <unavailable>       [pid 13833] <... futex resumed>)        = ?                     [pid 13832] <... futex resumed>)        = ?                     [pid 13830] <... futex resumed>)        = ? <unavailable>       [pid 13823] <... exit_group resumed>)   = ?                     [pid 13841] <... ioctl resumed> <unfinished ...>) = ?           [pid 13839] <... futex resumed>)        = ?                     [pid 13838] <... futex resumed>)        = ?                     [pid 13836] <... futex resumed>)        = ?                     [pid 13835] <... rt_sigtimedwait resumed> <unfinished ...>) = ? [pid 13837] <... futex resumed>)        = ?                     [pid 13833] +++ exited with 0 +++                               [pid 13832] +++ exited with 0 +++                               [pid 13831] <... futex resumed>)        = ?                     [pid 13841] +++ exited with 0 +++                               [pid 13840] +++ exited with 0 +++                               [pid 13839] +++ exited with 0 +++                               [pid 13838] +++ exited with 0 +++                               [pid 13837] +++ exited with 0 +++                               [pid 13836] +++ exited with 0 +++                               [pid 13835] +++ exited with 0 +++                               [pid 13834] +++ exited with 0 +++                               [pid 13831] +++ exited with 0 +++                               [pid 13830] +++ exited with 0 +++                               [pid 13823] +++ exited with 0 +++                               [pid 13820] <... accept4 resumed>0x7fd59b89f0, [110], 0) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)

rocket-pig avatar Sep 07 '23 16:09 rocket-pig

Long hold on terminal and then Report Issue with debug enabled. Then save file from options button in report activity.

agnostic-apollo avatar Sep 07 '23 17:09 agnostic-apollo

Long hold on terminal and then Report Issue with debug enabled. Then save file from options button in report activity.

...heres the result of that (400K+):

https://pastebin.com/awxp0Xbh

rocket-pig avatar Sep 07 '23 17:09 rocket-pig

...and just to skip that possible suggestion, i see it says in there that termux-am package is updateable, so i did, and ran termux-api stop; termux-api start; termux-sms-list and...its been over a minute with no response at all still.

rocket-pig avatar Sep 07 '23 17:09 rocket-pig

@rocket-pig To catch the long strace log, use strace -f -o strace-log.txt your-command. Then upload file strace-log.txt.

mprotect lines possibly related to /system/bin/app_process. This utility will generate lots of calls.

sylirre avatar Sep 07 '23 18:09 sylirre

@rocket-pig To catch the long strace log, use strace -f -o strace-log.txt your-command. Then upload file strace-log.txt.

mprotect lines possibly related to /system/bin/app_process. This utility will generate lots of calls.

Tldr my post above, i did that and its multiple MBs and couldn't get it here or on any paste sites.

rocket-pig avatar Sep 07 '23 20:09 rocket-pig

Change log level to Verbose for Termux:API and then run api command and then run adb logcat -d > logcat.txt. After that, install Termux:API app from here and then start app from launcher and then try running command again.

https://github.com/termux/termux-app#debugging

agnostic-apollo avatar Sep 08 '23 00:09 agnostic-apollo

I appreciate the help, updating to that version fixed the problem, maybe could have led with that lol.

FWIW Chrome seems incapable of clicking the .apk links on those Action pages, but in Brave browser they always work.

Thanks again.

rocket-pig avatar Sep 08 '23 02:09 rocket-pig

Welcome. Logs would have been useful to find real issue.

Probably aren't logged into github on chrome.

agnostic-apollo avatar Sep 08 '23 02:09 agnostic-apollo

Change log level to Verbose for Termux:API and then run api command and then run adb logcat -d > logcat.txt. After that, install Termux:API app from here and then start app from launcher and then try running command again.

https://github.com/termux/termux-app#debugging

Thank you very much! It fixed the problem for me too!

machitgarha avatar Oct 19 '23 12:10 machitgarha

I have incurred in the same issue, is there a fix that I could apply? In my case I use termux-api just to show some popups with termux-toast. I'm on Pixel 7 with Android 14, no root, Termux installed via F-Droid and termux-api installed with this version: termux-api/stable,now 0.57 aarch64 [installed]

suikoy avatar Dec 22 '23 19:12 suikoy

@suikoy, try this command: apt update; apt install termux-api termux-am As written in the https://github.com/termux/termux-api/issues/638#issuecomment-1868383070 It helped me

DobryninVyacheslav avatar Dec 24 '23 06:12 DobryninVyacheslav

Yes it works like a charm! Many thanks Dobrynin

suikoy avatar Dec 24 '23 11:12 suikoy

To address the issue of termux-api commands not working and hanging in the terminal without any visible output, I suggest the following solution:

1- Uninstall the termux app from your device. 2- Install the latest version of termux-api from F-Droid. 3- After installing termux-api, install the latest version of the termux app from F-Droid.

I followed this procedure on my Redmi 10c device running Android 13 and was able to resolve the issue.

amirhosein-vedadi avatar Apr 24 '24 20:04 amirhosein-vedadi