Giszmo Giszmo - 2 months ago 13
Android Question

adb hangs when trying to start or stop server

(This question definitely is related to ADB is not starting (no error message) but there is no clear explanation what fixed the issue and reinstalling over and over again doesn't convince me.)

When I run my usual

$ sudo adb kill-server && sudo adb start-server


I have to CTRL-C it.

the suggested adb_trace álà the other question yields this:

# export ADB_TRACE=all
# adb start-server
system/core/adb/adb.c::main():Handling commandline()
system/core/adb/adb_client.c::_adb_connect():_adb_connect: host:version
system/core/adb/transport.c::writex():writex: fd=3 len=4: 30303063 000c
system/core/adb/transport.c::writex():writex: fd=3 len=12: 686f73743a76657273696f6e host:version
system/core/adb/transport.c::readx():readx: fd=3 wanted=4 <---- freezes here


strace is slightly more verbose and I get this:

# strace /home/leo/Downloads/android-sdk-linux/platform-tools/adb start-server
... many
... many
... lines
futex(0xffab8474, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 1, NULL, f742a700) = -1 EAGAIN (Resource temporarily unavailable)
rt_sigaction(SIGRTMIN, {0xf77525f0, [], SA_SIGINFO}, NULL, 8) = 0
rt_sigaction(SIGRT_1, {0xf7752680, [], SA_RESTART|SA_SIGINFO}, NULL, 8) = 0
rt_sigprocmask(SIG_UNBLOCK, [RTMIN RT_1], NULL, 8) = 0
getrlimit(RLIMIT_STACK, {rlim_cur=-4286578688, rlim_max=-9223372032703125888}) = 0
uname({sys="Linux", node="donleo", ...}) = 0
socket(PF_INET, SOCK_STREAM, IPPROTO_IP) = 3
connect(3, {sa_family=AF_INET, sin_port=htons(5037), sin_addr=inet_addr("127.0.0.1")}, 16) = 0
write(3, "000c", 4) = 4
write(3, "host:version", 12) = 12
read(3, <---- freezes here


So, what next?

Another observation when trying to fix this issue was that updating the sdk via the sdk manager failed. It tells me that I have Android SDK Platform-tools 16.0.2 and wants to update to 17. Clicking install just hangs forever without doing anything. I assume that both actions indefinitely wait for an answer from the same component. [Update: ] Deleting the component worked. Installing it now showed an issue (in contrast to update which did not show any "red" line in the log) saying that stopping adb does not worked. After killing the adb the update went through but adb still refuses to work.

Update: The suspicion that my installation of adb itself might be broken can be ruled out I guess. I'm using the manual download of the SDK and just tried the adb from the ubuntu repository (4.2.2+git20130218-3ubuntu1) and this hangs at exactly the same spot.

Answer

Found it. In the style of the very educative comment on a bug report:

~# adb devices
adb.c::main():Handling commandline()
adb_client.c::adb_query():adb_query: host:devices
adb_client.c::_adb_connect():_adb_connect: host:version
transport.c::writex():writex: fd=3 len=4: 30303063 000c
transport.c::writex():writex: fd=3 len=12: 686f73743a76657273696f6e host:version
transport.c::readx():readx: fd=3 wanted=4
^Z          
[1]+  Stopped                 adb devices

Hmm... file descriptor 3?

# pgrep adb
5982
# ls -l /proc/5982/fd/
total 0
lrwx------ 1 root root 64 Jun 14 18:04 0 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 14 18:04 1 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 14 18:04 2 -> /dev/pts/0
lrwx------ 1 root root 64 Jun 14 18:04 3 -> socket:[96863]

socket 96863?

# lsof | grep 96863
lsof: WARNING: can't stat() fuse.gvfsd-fuse file system /run/user/leo/gvfs
      Output information may be incomplete.

adb       5982            root    3u     IPv4              96863       0t0        TCP localhost:55463->localhost:5037 (ESTABLISHED)
# netstat -antp | grep LISTEN | grep 5037
tcp6       0      0 :::5037                 :::*                    LISTEN      2419/java       

ava? java what?

# ps -Alf | grep java
1 S root      2409     1  0  80   0 -  4620 hrtime 16:20 ?        00:00:07 /opt/traccar/bin/./wrapper /opt/traccar/bin/../conf/wrapper.conf wrapper.syslog.ident=traccar wrapper.pidfile=/opt/traccar/bin/./traccar.pid wrapper.name=traccar wrapper.displayname=traccar wrapper.daemonize=TRUE wrapper.statusfile=/opt/traccar/bin/./traccar.status wrapper.java.statusfile=/opt/traccar/bin/./traccar.java.status wrapper.script.version=3.5.19
0 S root      2419  2409  0  80   0 - 810286 futex_ 16:20 ?       00:00:41 /usr/lib/jvm/java-6-oracle/jre/bin/java -Djava.library.path=../lib -classpath ../lib/wrapper.jar:../tracker-server.jar -Dwrapper.key=ja2Mz5xiI18XmG4C -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.disable_console_input=TRUE -Dwrapper.pid=2409 -Dwrapper.version=3.5.19 -Dwrapper.native_library=wrapper -Dwrapper.arch=x86 -Dwrapper.service=TRUE -Dwrapper.cpu.timeout=10 -Dwrapper.jvmid=1 org.tanukisoftware.wrapper.WrapperSimpleApp org.traccar.Main /opt/traccar/conf/traccar.cfg
0 S leo       3549  3421  2  80   0 - 853194 futex_ 16:24 ?       00:02:59 /usr/bin/java -Xms40m -Xmx512m -XX:MaxPermSize=256m -jar /home/leo/Downloads/eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar -os linux -ws gtk -arch x86_64 -showsplash /home/leo/Downloads/eclipse//plugins/org.eclipse.platform_4.2.2.v201302041200/splash.bmp -launcher /home/leo/Downloads/eclipse/eclipse -name Eclipse --launcher.library /home/leo/Downloads/eclipse//plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.200.v20120913-144807/eclipse_1502.so -startup /home/leo/Downloads/eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar --launcher.overrideVmargs -exitdata 148007 -vm /usr/bin/java -vmargs -Xms40m -Xmx512m -XX:MaxPermSize=256m -jar /home/leo/Downloads/eclipse//plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar
0 S root      6280  4662  0  80   0 -  2360 pipe_w 18:24 pts/0    00:00:00 grep --color=auto java

grrrrr! Why? Why? Why is there no timeout or something in adb? Why does traccar – a software that also has an Android client – use ADB's port 5037 for its IntelliTrac component? They use all ports 5000 through 5040.

# /etc/init.d/traccar stop
Stopping traccar...
Stopped traccar.
# adb start-server
# adb devices

List of devices attached 
016814F11001F009    device
Comments