Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many TIME_WAIT state. #173

Open
kysersozelee opened this issue Feb 4, 2016 · 5 comments
Open

Too many TIME_WAIT state. #173

kysersozelee opened this issue Feb 4, 2016 · 5 comments

Comments

@kysersozelee
Copy link

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?

@dtmilano
Copy link
Owner

dtmilano commented Feb 4, 2016

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.

@kysersozelee
Copy link
Author

kysersozelee commented Feb 5, 2016


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
Copy link
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.

@kysersozelee
Copy link
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

`

dtmilano added a commit that referenced this issue Feb 11, 2016
@dtmilano
Copy link
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants