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

Cause & solution for "inflater has been closed" exceptions found? #286

Open Gintasz opened 6 years ago

Gintasz commented 6 years ago

I can't pinpoint the problem, but literally, one launch it's working 100% fine 10/10 no problem, 2nd launch (no code change) I get random "Inflater has been closed" exceptions. Anyone experienced it? Would love to keep using jBrowserDriver, but I gotta fix this

Gintasz commented 6 years ago

Might be a coincidence, but it seems to occur less when Connection: keep-alive header is removed? I remove it with Settings.builder().requestHeaders() by passing default CHROME ones but with "Connection" header removed. I'm also using a proxy.

edit: fake news

Gintasz commented 6 years ago

FOUND IT! I just did ~50 tries/launches with and without Connection header in main thread, separate thread, all worked 100% fine. Then I started cleaning up code, removed these lines:

Settings settings = Settings.builder()
                .proxy(new ProxyConfig(ProxyConfig.Type.HTTP, "hidden", 4444, "hidden", "hidden"))
                .userAgent(UserAgent.CHROME)
//                .socketTimeout(15000) // this
//                .connectTimeout(10000) // this
//                .connectionReqTimeout(5000) // this
//                .ajaxResourceTimeout(15000) // this
                .build();

and it immediatelly started crashing, only 2/10 succeeded. Literally, these timeout settings somehow fix the whole problem.

P. S. I'm testing with URL "https://accounts.google.com/signin/v2"

@hollingsworthd

hollingsworthd commented 6 years ago

This has been a longstanding issue and your info provides some excellent clues as to what the root cause might be. Anyone using Apache HttpComponents coming across this page from googling should take note.

dlaske commented 6 years ago

@hollingsworthd i think i found the reason for this problem. http://bugs.java.com/view_bug.do?bug_id=7003462 Here is an example how you can reproduce it.

In this Method StreamConnection.getInputStream() you got the same Inputstream twice and open it with the GZIPInputStream and i think this will be the problem with the closed Inflater. Now you have to prevent that the same Inputstream will be used twice.

Gintasz commented 6 years ago

@dlaske try fixing it, if it works, do a commit or post the fixed code here. I would very much appreciate it. These timeout settings of mine don't fix it 100% of the time, I still get it, but just little bit bigger success chance.

hfcipriano commented 5 years ago

I have the same problem, even assigning the timeout values. :/