question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Java Client 6.0.0: createSession exceptions throw odd WebDriverException

See original GitHub issue

The problem

If createSession throws an exception (in my case we hit a 10 minute timeout), the end exception has incorrect message in the WebDriver Exception.

Real Message:

Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Command duration or timeout: 600.10 seconds

WebDriverException Message:

Caused by: org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: IOSDriver

Full Stack:

Caused by: org.openqa.selenium.WebDriverException: It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: IOSDriver
        at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:182)
        at io.appium.java_client.remote.AppiumCommandExecutor.createSession(AppiumCommandExecutor.java:196)
        at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:218)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
        at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
        at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
        at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:207)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:130)
        at io.appium.java_client.DefaultGenericMobileDriver.<init>(DefaultGenericMobileDriver.java:38)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:84)
        at io.appium.java_client.AppiumDriver.<init>(AppiumDriver.java:94)
        at io.appium.java_client.ios.IOSDriver.<init>(IOSDriver.java:90)
        at com.tripadvisor.qa.mobile.common.appium.AppiumDriverFactory.lambda$createDriver$1(AppiumDriverFactory.java:169)
        ... 4 common frames omitted
Caused by: java.lang.reflect.InvocationTargetException: null
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at io.appium.java_client.remote.AppiumCommandExecutor$1.createSession(AppiumCommandExecutor.java:172)
        ... 18 common frames omitted
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Command duration or timeout: 600.10 seconds
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
        at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
        at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$new$0(JsonWireProtocolResponse.java:53)
        at org.openqa.selenium.remote.JsonWireProtocolResponse.lambda$getResponseFunction$2(JsonWireProtocolResponse.java:91)
        at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:123)
        at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
        at java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:958)
        at java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:126)
        at java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:498)
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:485)
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
        at java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:152)
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:464)
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
        ... 23 common frames omitted
Caused by: org.openqa.selenium.WebDriverException: Error forwarding the new session Error forwarding the request unexpected end of stream on Connection{10.96.80.60:4848, proxy=DIRECT hostAddress=/10.96.80.60:4848 cipherSuite=none protocol=http/1.1}
Build info: version: '3.12.0', revision: '7c6e0b3', time: '2018-05-08T14:04:26.12Z'
System info: host: 'vr-qa05.dhcp.tripadvisor.com', ip: '10.96.81.45', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.13.4', java.version: '1.8.0_144'
Driver info: driver.version: unknown
        at org.openqa.grid.web.servlet.handler.RequestHandler.process(RequestHandler.java:118)
        at org.openqa.grid.web.servlet.DriverServlet.process(DriverServlet.java:86)
        at org.openqa.grid.web.servlet.DriverServlet.doPost(DriverServlet.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:860)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:535)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
        at org.seleniumhq.jetty9.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:473)
        at org.seleniumhq.jetty9.server.session.SessionHandler.doScope(SessionHandler.java:1564)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.seleniumhq.jetty9.server.Server.handle(Server.java:530)
        at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:347)
        at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:256)
        at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
        at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:102)
        at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
        at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:247)
        at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:140)
        at org.seleniumhq.jetty9.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:131)
        at org.seleniumhq.jetty9.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:382)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:708)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:626)
        ... 1 common frames omitted

Code that causes this: AppiumCommandExecutor Line 156-191

                FileBackedOutputStream os = new FileBackedOutputStream(threshold);
                try {

                    CountingOutputStream counter = new CountingOutputStream(os);
                    Writer writer = new OutputStreamWriter(counter, UTF_8);
                    NewAppiumSessionPayload payload = NewAppiumSessionPayload.create(desired);
                    payload.writeTo(writer);

                    try (InputStream rawIn = os.asByteSource().openBufferedStream();
                         BufferedInputStream contentStream = new BufferedInputStream(rawIn)) {

                        Method createSessionMethod = this.getClass().getSuperclass()
                                .getDeclaredMethod("createSession", HttpClient.class, InputStream.class, long.class);
                        createSessionMethod.setAccessible(true);

                        Optional<Result> result = (Optional<Result>) createSessionMethod
                                .invoke(this, client, contentStream, counter.getCount());

                        return result.map(result1 -> {
                            Result toReturn = result.get();
                            getLogger(ProtocolHandshake.class.getName())
                                    .info(format("Detected dialect: %s", toReturn.getDialect()));
                            return toReturn;
                        }).orElseThrow(() -> new SessionNotCreatedException(
                                format("Unable to create new remote session. desired capabilities = %s", desired)));
                    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
                        throw new WebDriverException(format("It is impossible to create a new session "
                                        + "because 'createSession' which takes %s, %s and %s was not found "
                                        + "or it is not accessible",
                                HttpClient.class.getSimpleName(),
                                InputStream.class.getSimpleName(),
                                long.class.getSimpleName()), e);
                    }
                } finally {
                    os.reset();
                }

Environment

  • Appium version (or git revision) that exhibits the issue: 1.8.1
  • Last Appium version that did not exhibit the issue (if applicable): (Unsure… I think this is java client related)
  • Desktop OS/version used to run Appium: osx 10.13.4
  • Node.js version (unless using Appium.app|exe): 8.11.1
  • Mobile platform/version under test: iPhone 7 IOS 11.3.1
  • Real device or emulator/simulator: Real Device
  • Appium CLI or Appium.app|exe: Appium CLI

Link to Appium logs

No link here currently… as this appears to be just incorrect error reporting (appium log mainly has retries trying to start the app… unsure if this is a separate issue or not

Code To Reproduce Issue [ Good To Have ]

No code here, just possibly a phone that’s not starting up the app correctly, so the createSession call to appium times out at 10 minutes

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:26 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
emreakcancommented, Jun 5, 2018

No idea but i go back to 6.0.0-BETA4, so no errors. implementation group: 'io.appium', name: 'java-client', version: '6.0.0-BETA4'

0reactions
SrinivasanTargetcommented, Jul 4, 2018

Tried with latest appium server beta

@junjunoori What did you actually tried? Did you tried creating session in grid? whats the logs?

I’m going to close this issue thread as there are lot of folks saying +1 without speaking about actual issue and what was tried and what desired caps been sent and whether is it on grid and some folks randomly spike on saying issue on parallel execution without giving enough info on whether parallel tried using grid or tried some other ways.

I’m not interested to have one confused issue thread rather i will open a new one and start giving all the info required to debug. Feel free to raise a new issue and i’m happy to discuss it there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebDriverException: It is impossible to create a new session ...
WebDriverException : It is impossible to create a new session because 'createSession' which takes HttpClient, InputStream and long was not found.
Read more >
Launching and stopping appium server programmtically
Mention below the code to run Appium with java ... Run the command client. ... WebDriverException: A exception with a null response was...
Read more >
How to Throw Exceptions in Java - Rollbar
Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception...
Read more >
Exceptions in Selenium Webdriver : How to Handle It
Here's a rundown of the 11 Common Exceptions in Selenium. Learn the basics of Exception Handling in Selenium using different methods.
Read more >
Checked Exceptions Rollback Transactions Since GORM 6.0.0
Groovy has less ceremony than Java. That's crystal-clear in exception handling. Java forces us to handle checked exceptions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found