selenium-google-code-issue-archive icon indicating copy to clipboard operation
selenium-google-code-issue-archive copied to clipboard

Selenium2 leaves open ports

Open lukeis opened this issue 8 years ago • 8 comments

Originally reported on Google Code with ID 7947

What steps will reproduce the problem?
1. Run selenium server
I use following command:
java -jar /path/to/selenium-server-standalone-2.41.0.jar -Dphantomjs.binary.path=/bin/phantomjs
-browserTimeout 300 -timeout 300

2. Create new WebDriver session (I use phantomjs as browser, and my application is
written in PHP, but it is not important I think).
During this step a new phantomjs process will be started. It will have a "--webdriver=PORT_NUMBER"
parameter. 

3. Stop WebDriver session 
That gracefully stops browser and should free port, used for webdriver communication.

4. Run "netstat -np" and search for PORT_NUMBER in step 2.
I get something like that:
Proto Recv-Q Send-Q Local Address                 Foreign Address                 State
      PID/Program name
tcp6       1      0 127.0.0.1:PORT_NUMBER         127.0.0.1:ANOTHER_PORT          CLOSE_WAIT
 PID_OF_STEP_1_PROCESS/java



Selenium version: 2.41.0
OS: Debian 6
Browser: phantomjs
Browser version: 1.7.9

Used connections are never closed, and in time (depends on my application activity)
I can't create sessions anymore (I have over 1000 CLOSE_WAIT ports used by java). 
When I try to create new session, I get "Unable to find a free port" exception in selenium
output (I have no trace saved, but if it is important, I can provide it).

For now, I just restart selenium every 2 days, but I think, it is a bad solution.

Here is related issue:
http://code.google.com/p/selenium/issues/detail?id=1209

Thanks.

Reported by yoursuffer on 2014-09-23 09:57:48

lukeis avatar Mar 04 '16 09:03 lukeis

Reported by barancev on 2014-09-23 10:24:55

  • Labels added: Component-Grid

lukeis avatar Mar 04 '16 09:03 lukeis

Here is selenium output for this situation:

http://pastebin.com/eCxRYDcV

Reported by yoursuffer on 2014-11-01 10:34:16

lukeis avatar Mar 04 '16 09:03 lukeis

We might be seeing this behaviour, too. We are running Selenium from Java. Have you
found any workaround for this?

Reported by [email protected] on 2015-01-07 08:06:10

lukeis avatar Mar 04 '16 09:03 lukeis

Oh, also, we are seeing this for phantomjs.

Reported by [email protected] on 2015-01-07 08:12:51

lukeis avatar Mar 04 '16 09:03 lukeis

FYI, it looks like we worked around our issue by calling `WebDriver#quit()` after `WebDriver#close()`.

Reported by [email protected] on 2015-01-08 10:08:08

lukeis avatar Mar 04 '16 09:03 lukeis

Thanks for this information.

Unfortunately, PHP implementations of webDriver protocol seem to have no Driver::quit()
method (I am using behat/mink package, it uses instaclick/php-webdriver WebDriver implementation).
But I can manually close windows using this implementation.
Also, I found following descriptions of quit() and close() methods (link: http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.html):

public void quit()
Quits this driver, closing every associated window.

public void close()
Close the current window, quitting the browser if it's the last window currently open.

In my case, there is only one opened window per browser. So, there should be no difference
between quit() and close() methods.

I tried to close active window before stopping session, but nothing changed.

But anyway, session is being destroyed, there are selenium logs:
INFO - Executing: [delete session: c95d6511-d21a-4749-b938-c7e6f2f4266a] at URL: /session/c95d6511-d21a-4749-b938-c7e6f2f4266a)
[INFO] ShutdownReqHand - _handle - About to shutdown
INFO - Done: /session/c95d6511-d21a-4749-b938-c7e6f2f4266a

Browser process is stopped too, but I keep geting new CLOSE_WAIT port.

Reported by yoursuffer on 2015-03-02 08:28:04

lukeis avatar Mar 04 '16 09:03 lukeis

i also get this problem.
i use selenium 2.45.0, but fail to fix it.

But there is a strange condition:
(1)When I use PhantomjsDriver to driver phantomjs, it leave open port with CLOSE_WAIT
condition.
(2)When I use ProcessBuilder to construct linux command and to driver phantomjs, it'f
fine.
The different for (1) & (2) is (1) is more stable.

I have no idea to solve it. The worst way to fix it is routing restart my app.>_<

Reported by welson327 on 2015-04-07 04:11:58

lukeis avatar Mar 04 '16 09:03 lukeis

Reported by luke.semerau on 2015-09-17 17:47:05

  • Labels added: Restrict-AddIssueComment-Commit

lukeis avatar Mar 04 '16 09:03 lukeis