AndroidViewClient icon indicating copy to clipboard operation
AndroidViewClient copied to clipboard

Too many TIME_WAIT state.

Open kysersozelee opened this issue 9 years ago • 5 comments

Hi. First of all, thanks for you greate library. It's very useful and giving a lot of greate functions to develope my project.

I have some problem, I wrote script for monkey test(doing irregular actions), and found it adbClient left a lots of ports TIME_WAIT. I guess it creates ports every function related adb command and left ports TIME_WAIT state. When I continued 12 hours for several devices, Number of TIME_WAIT state ports are over 30 thoundans. So I guess It can cause lacks of ports. I want decrese thoses.

Could you comment about this issue please?

kysersozelee avatar Feb 04 '16 15:02 kysersozelee

Can you please provide the source code (perhaps only the relevant part) of your test script?

I have been running tests for hour and even days with no problems so I think the reason might be the way you are using it.

dtmilano avatar Feb 04 '16 15:02 dtmilano


class Action(object):

    @staticmethod
    def runMonkeyTest(testManager, seq, duration, testReport_id, scriptLogPath):
            while substractTime < duration:
                if monkeyAction == 1 :
                     #do action
                   captureScreenImageAndSaveFile(...)
                    if not Galileo_Action.tap(testManager, [(xPos, yPos)], 500):
                        pass
                if monkeyAction == 2 :
                    #do action
                   captureScreenImageAndSaveFile(...)
                   if not Galileo_Action.swipe(testManager, (xPos , yPos), (xPos2, yPos2), swipeDuration):
                        pass

...                

kysersozelee avatar Feb 05 '16 01:02 kysersozelee

  1. Set AdbClient Instance (adbclient.py > def __init(self, ...)
  • 53863 port opened at "self.socket = AdbClient.connect(self.hostname, self.port, self.timeout)" line156.
  • "self.checkVersion(ignoreversioncheck)" function called and 53863 turn to TIME_WAIT state, and new port 53869 are oppend.

aftercheckversion reconnecttrue

  1. After "devices = self.getDevices()" called, new port is opeend. (adbclient.py > def __setTransport(self))
  • If I pass "reconnect=True" argument, It cause recursion error
    def getDevices(self):
        if DEBUG:
            print >> sys.stderr, "getDevices()"
        self.__send('host:devices-l', checkok=False, **reconnect=True**)

aftergetdevice

  1. I'm worried about this issues repeat, so huge ports are stayed at TIME_WAIT state.

kysersozelee avatar Feb 05 '16 02:02 kysersozelee

It caused by graceful shutdown when send&recv with adb server(5037). It's absolutely normal process I guess. But in my case, it cause throttling, so I set linger option when connect socket. It makes a new connection not left TIME_WAIT port.

`

def connect(hostname, port, timeout=TIMEOUT):
    if DEBUG:
        print >> sys.stderr, "AdbClient.connect(%s, %s, %s)" % (hostname, port, timeout)
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    l_onoff = 1
    l_linger = 0
    s.setsockopt(socket.SOL_SOCKET, socket.SO_LINGER,                                                                                                                     
             struct.pack('ii', l_onoff, l_linger))
    s.settimeout(timeout)
    try:
        s.connect((hostname, port))
    except socket.error, ex:
        raise RuntimeError("ERROR: Connecting to %s:%d: %s.\nIs adb running on your computer?" % (s, port, ex))
    return s

`

kysersozelee avatar Feb 11 '16 03:02 kysersozelee

It seems like a good idea. I've created the patch (3f1f2864124c6d62c0f24c77058c478e9880287b) and gave you credit. Thanks.

dtmilano avatar Feb 11 '16 07:02 dtmilano