SeleniumHQ / selenium-google-code-issue-archive

Archive, please see main selenium repo
https://github.com/seleniumhq/selenium
345 stars 195 forks source link

SeleniumServer fails to stop() #2724

Closed lukeis closed 8 years ago

lukeis commented 8 years ago

Originally reported on Google Code with ID 2724

What steps will reproduce the problem?
1. JUnit test suite with parallel execution of Selenium tests. I am using a fixed thread
pool with 2 threads to execute the test.
2. Call SeleniumServer.stop() at the end of the last test (tear down of suite).
3. In a high percentage of the test runs (at least 30%) SeleniumServer.stop() never
returns.
4. I executed the test in Eclipse debug mode and suspended the vm to get the stacktraces.

What is the expected output? 
All browser windows are closed, SeleniumServer.stop() returns.

What do you see instead?
The last browser window is left open, SeleniumServer.stop() never returns.

Selenium version: 2.8.0
OS: Windows XP SP 3
Browser: Firefox
Brower version: 3.6.23

I am using JDK 1.6, with Java RC and the standalone Selenium server jar.

Stacktraces when SeleniumServer.stop() hangs:
---------------------------------------------

Thread [main] (Suspended)   
    FileInputStream.close0() line: not available [native method]    
    FileInputStream.close() line: 259   
    BufferedInputStream.close() line: 451   
    Closeables.close(Closeable, boolean) line: 79   
    Closeables.closeQuietly(Closeable) line: 98 
    ProcessUtils.closeAllStreamsAndDestroyProcess(Process) line: 168    
    AsyncExecute.killProcess(Process) line: 72  
    FirefoxChromeLauncher.killFirefoxProcess() line: 294    
    FirefoxChromeLauncher.close() line: 257 
    FirefoxLauncher.close() line: 105   
    BrowserSessionFactory.shutdownBrowserAndClearSessionData(BrowserSessionFactory$BrowserSessionInfo)
line: 245   
    BrowserSessionFactory.endBrowserSession(boolean, String, RemoteControlConfiguration,
boolean) line: 204  
    BrowserSessionFactory.endBrowserSession(boolean, String, RemoteControlConfiguration)
line: 186   
    BrowserSessionFactory.endAllBrowserSessions(RemoteControlConfiguration) line: 158   
    SeleniumDriverResourceHandler.stopAllBrowsers() line: 880   
    SeleniumServer.stop() line: 533 
        ...

2 * Thread [Thread-17] (Suspended)  
    ProcessImpl.waitFor() line: not available [native method]   
    CommandLine.waitFor() line: 201 
    CommandLine.access$2(CommandLine) line: 199 
    CommandLine$1.run() line: 178   

2 * Thread [Command line drainer: C:\Programme\Mozilla Firefox\firefox.exe] (Suspended) 
    FileInputStream.readBytes(byte[], int, int) line: not available [native method] 
    FileInputStream.read(byte[], int, int) line: 199    
    BufferedInputStream.read1(byte[], int, int) line: 256   
    BufferedInputStream.read(byte[], int, int) line: 317    
    BufferedInputStream.fill() line: 218    
    BufferedInputStream.read1(byte[], int, int) line: 258   
    BufferedInputStream.read(byte[], int, int) line: 317    
    BufferedInputStream(FilterInputStream).read(byte[]) line: 90    
    CommandLine$StreamDrainer.run() line: 345   
    Thread.run() line: 619  

Daemon System Thread [Finalizer] (Suspended)    
    SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available
[native method] 
    SocketInputStream.read(byte[], int, int) line: 129  
    BufferedInputStream.fill() line: 218    
    BufferedInputStream.read1(byte[], int, int) line: 258   
    BufferedInputStream.read(byte[], int, int) line: 317    
    HttpClient.parseHTTPHeader(MessageHeader, ProgressSource, HttpURLConnection) line:
687 
    HttpClient.parseHTTP(MessageHeader, ProgressSource, HttpURLConnection) line: 632    
    HttpURLConnection.getInputStream() line: 1072   
    HttpURLConnection(HttpURLConnection).getResponseCode() line: 373    
    HttpCommandProcessor.getResponseCode(HttpURLConnection) line: 159   
    HttpCommandProcessor.getCommandResponseAsString(String) line: 179   
    HttpCommandProcessor.executeCommandOnServlet(String) line: 118  
    HttpCommandProcessor.doCommand(String, String[]) line: 101  
    HttpCommandProcessor.stop() line: 265   
    VSSelenium(DefaultSelenium).stop() line: 132    
    SeleniumClientFactory.stop() line: 195  
    SeleniumClientFactory.finalize() line: 178  
    Finalizer.invokeFinalizeMethod(Object) line: not available [native method]  
    Finalizer.runFinalizer() line: 83   
    Finalizer.access$100(Finalizer) line: 14    
    Finalizer$FinalizerThread.run() line: 160   

Thread [ReaderThread] (Suspended)   
    SocketInputStream.socketRead0(FileDescriptor, byte[], int, int, int) line: not available
[native method] 
    SocketInputStream.read(byte[], int, int) line: 129  
    StreamDecoder.readBytes() line: 264 
    StreamDecoder.implRead(char[], int, int) line: 306  
    StreamDecoder.read(char[], int, int) line: 158  
    InputStreamReader.read(char[], int, int) line: 167  
    BufferedReader.fill() line: 136 
    BufferedReader.readLine(boolean) line: 299  
    BufferedReader.readLine() line: 362 
    RemoteTestRunner$ReaderThread.run() line: 140   

Reported by markus@markusheiden.de on 2011-10-27 09:41:59

lukeis commented 8 years ago
This looks like the stream handling problem of ProcessBuilder. Has been proposed fixed
by switching to commons-exec

Reported by kristian.rosenvold@zenior.no on 2011-10-27 14:27:47

lukeis commented 8 years ago
Are you sure you're terminating the browser sessions before trying to close the server
? Make sure the browser windows are closed by calling either selenium.stop() or webDriver.quit()
from the tests before you try to close the server. Does this help ?

Reported by kristian.rosenvold on 2011-10-27 16:03:09

lukeis commented 8 years ago
I am not closing the windows before SeleniumServer.stop(). But I used to to close the
browser window, when a test failed. This led to a lockup too, so I think this would
not solve the problem.

What I forgot to mention: If I close the last browser window by hand, the tests successfully
finish.

Reported by markus@markusheiden.de on 2011-10-27 17:03:33

lukeis commented 8 years ago
You should close the window using either selenium.stop or webDriver.quit. The selenium
server /requires/ proper termination of sessions. So technically you are running into
the ProcessBuilder problem, but it is only because your tests are not properly written.

We will be fixing the ProcessBuilder problem, but this is not to support this use-case
in specific. I do not know what other problems you were experiencing, to my best knowledge
all supported versions of firefox work well in parallel. 

Whatever lockup you are experiencing if you actually properly terminate the sessions
is more interesting.

I will leave this issue as "NeedsClarification" for a few days, but will close this
as invalid unless you want to submit additional details about hanging when writing
the tests correctly. If you feel that there is incomplete documentation somewhere regarding
proper termination of the sessions, please include a link to the documentation in question
and we will update it.

Reported by kristian.rosenvold on 2011-10-27 18:40:28

lukeis commented 8 years ago
I'll will fix the code and retry tomorrow. But as I mentioned already, I got problems
with selenium.stop() too.

Reported by markus@markusheiden.de on 2011-10-27 20:24:15

lukeis commented 8 years ago

Reported by barancev on 2011-10-28 16:31:11

lukeis commented 8 years ago
I am now closing all Selenium instances before stopping the server and now it works.

Reported by markus@markusheiden.de on 2011-11-01 13:05:04

lukeis commented 8 years ago
Documentation page for server updated to stress the importance of properly terminating
sessions. Marked issue as invalid. 

Reported by kristian.rosenvold on 2011-11-01 13:22:14

lukeis commented 8 years ago

Reported by luke.semerau on 2015-09-17 18:13:59