MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

Attempted read from closed stream. #280

Open dan335 opened 7 years ago

dan335 commented 7 years ago

I sometime see this error. Seems to happen randomly.

 java.io.IOException: Attempted read from closed stream. 
    at org.apache.http.impl.io.ContentLengthInputStream.read(ContentLengthInputStream.java:167) 
    at org.apache.http.conn.EofSensorInputStream.read(EofSensorInputStream.java:137) 
    at com.machinepublishers.jbrowserdriver.Util.toBytes(Util.java:98) 
    at com.machinepublishers.jbrowserdriver.ResponseHandler.handleResponse(ResponseHandler.java:52) 
    at com.machinepublishers.jbrowserdriver.StreamConnection.getInputStream(StreamConnection.java:408) 
    at com.sun.webkit.network.URLLoader.receiveResponse(URLLoader.java:507) 
    at com.sun.webkit.network.URLLoader.doRun(URLLoader.java:164) 
    at com.sun.webkit.network.URLLoader.lambda$run$0(URLLoader.java:129) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.webkit.network.URLLoader.run(URLLoader.java:128) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:748) 

Here's the code.

public String fetch() {
    Settings settings = Settings.builder().timezone(Timezone.AMERICA_NEWYORK).build();
    JBrowserDriver driver = new JBrowserDriver(settings);
    driver.get(url);
    System.out.println("status code: " + driver.getStatusCode());
    String html = driver.getPageSource();
    driver.quit();
    return html;
}

I also sometimes see status code 499 and sometimes 200.

499 CLIENT CLOSED REQUEST
A non-standard status code introduced by nginx for the case when a client closes the connection while nginx is processing the request.
hollingsworthd commented 7 years ago

Status code 499 is used by this project for certain errors and most likely unrelated to nginx's use of it.

The "attempted to read from closed stream" might be this project using Apache HTTP Components in an incorrect way in some cases (perhaps consuming the response entity more than once). Not sure on that.