Skip to content

Too many TIME_WAIT state. #173

Description

@kysersozelee

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?

Activity

  1. dtmilano commented on Feb 4, 2016

    @dtmilano
    Owner

    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.

  2. kysersozelee commented on Feb 5, 2016

    @kysersozelee
    Author
    
    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
    
    ...                
    
    
  3. kysersozelee commented on Feb 5, 2016

    @kysersozelee
    Author
    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.
  4. kysersozelee commented on Feb 11, 2016

    @kysersozelee
    Author

    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
    

    `

  5. dtmilano commented on Feb 11, 2016

    @dtmilano
    Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions