Hi,
I am using ddmlib to monitor devices and applications, more specifically im starting and stopping method tracing in specific apps.
The platform where we use ddmlib is launching and killing Android VMs, while also installing apps to be traced.
For that purpose I have a long lived process always listening for app clients (using the default ddmlib listeners).
While i do get a few non-breaking exceptions (broken pipe and BufferOverflowExceptions from within ddmlib), one in particular breaks the library:
Exception in thread "Device Client Monitor" java.lang.IllegalArgumentException: port out of range:65536
at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)
at java.net.InetSocketAddress.<init>(InetSocketAddress.java:188)
at com.android.ddmlib.Debugger.<init>(Debugger.java:73)
at com.android.ddmlib.Client.listenForDebugger(Client.java:605)
at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:561)
at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:544)
at com.android.ddmlib.DeviceMonitor.processIncomingJdwpData(DeviceMonitor.java:506)
at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:402)
at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:64)
at com.android.ddmlib.DeviceMonitor$1.run(DeviceMonitor.java:325)
So apparently ddmlib runs out of ports to use. I used a bit of reflection to retrieve the DebuggerPort list of available ports and plotted the maximum observed port over time:
The number of clients and devices are as reported by the AndroidDebugBridge.getDevices(), which i iterate to retrieve the clients.
So at any given time there is a max of 186 clients even though the ports getting attributed are already close to 10K higher.
In theory the ports should be released when the MonitorThread drops the client (dropClient()) or in the case communication (handshake of JDWP packets) goes wrong.
Am I missing something? (should i manually release these clients?)
I leave the other common exceptions:
java.nio.BufferOverflowException
at java.nio.HeapByteBuffer.put(HeapByteBuffer.java:206)
at com.android.ddmlib.JdwpPacket.movePacket(JdwpPacket.java:235)
at com.android.ddmlib.Debugger.sendAndConsume(Debugger.java:347)
at com.android.ddmlib.Client.forwardPacketToDebugger(Client.java:709)
at com.android.ddmlib.MonitorThread.processClientActivity(MonitorThread.java:346)
at com.android.ddmlib.MonitorThread.run(MonitorThread.java:265)
I assume the following is due to a VM being killed or app crashing :
java.io.IOException: Broken pipe
at sun.nio.ch.FileDispatcherImpl.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:47)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:65)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:471)
at com.android.ddmlib.JdwpPacket.writeAndConsume(JdwpPacket.java:213)
at com.android.ddmlib.Client.sendAndConsume(Client.java:686)
at com.android.ddmlib.HandleHeap.sendREAQ(HandleHeap.java:349)
at com.android.ddmlib.Client.requestAllocationStatus(Client.java:525)
at com.android.ddmlib.DeviceMonitor.createClient(DeviceMonitor.java:569)
at com.android.ddmlib.DeviceMonitor.openClient(DeviceMonitor.java:544)
at com.android.ddmlib.DeviceMonitor.deviceClientMonitorLoop(DeviceMonitor.java:360)
at com.android.ddmlib.DeviceMonitor.access$100(DeviceMonitor.java:64)
at com.android.ddmlib.DeviceMonitor$1.run(DeviceMonitor.java:325)
Thanks in advance!