Skip to content

Do not set content length to zero #11417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

krmahadevan
Copy link
Contributor

Fixes: #11342

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@krmahadevan
Copy link
Contributor Author

@pujagani @diemol - I haven't been able to figure out a proper way to test this functionality manually because I basically need to create selenium/standalone-firefox docker image with the newly built jar and then use that.

I attempted the following but this generates an error saying

grid-node-docker-1    | 06:36:35.008 WARN [SessionSlot.apply] - Unable to create session
grid-node-docker-1    | java.lang.IllegalArgumentException: Assets path must be set
grid-node-docker-1    |         at org.openqa.selenium.internal.Require.nonNull(Require.java:59)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.docker.DockerSession.<init>(DockerSession.java:61)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.docker.DockerSessionFactory.apply(DockerSessionFactory.java:269)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.docker.DockerSessionFactory.apply(DockerSessionFactory.java:90)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.local.SessionSlot.apply(SessionSlot.java:147)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.local.LocalNode.newSession(LocalNode.java:382)
grid-node-docker-1    |         at org.openqa.selenium.grid.node.NewNodeSession.execute(NewNodeSession.java:52)
grid-node-docker-1    |         at org.openqa.selenium.remote.http.Route$TemplatizedRoute.handle(Route.java:192)

Steps:

  1. Built the grid jar (bazel build grid)
  2. cloned the docker selenium project
  3. copied the selenium grid jar to the Base folder in the docker selenium project
  4. Altered the Dockerfile in this directory to refer to the local jar instead of downloading it from Maven central.
  5. Built all the images by running VERSION=local make build
  6. Altered the docker compose file and the config.toml (references of them are available in the defect ) to refer to the local images.
  7. Started the grid via docker compose
  8. Ran a sample test that looks like below
  public static void main(String[] args) throws MalformedURLException {
    RemoteWebDriver driver = null;
    try {
      driver = new RemoteWebDriver(new URL("http://localhost:4444"), new FirefoxOptions());
      driver.get("http://www.google.com");
      System.err.println("Title " + driver.getTitle());
    } finally {
      if (driver != null) {
        driver.quit();
      }
    }
  }

@krmahadevan
Copy link
Contributor Author

Ok please ignore the error msg.. That was my mistake... I didnt add a volume for mapping the assets in my docker compose file.

Once I added it

    volumes:
      - ./config.toml:/opt/bin/config.toml
      - ./assets:/opt/selenium/assets

It worked fine.. a test runs fine.. That PR is now tested out.. I am able to run a firefox test inside a dynamic grid without any issues.

@jsa34
Copy link

jsa34 commented Dec 14, 2022

Came across this, too, after updating thinking the issue was resolved with latest release. Could this be reviewed/merged/released ASAP?

@titusfortner titusfortner added this to the 4.8 milestone Dec 14, 2022
@diemol diemol force-pushed the remote_content_length_setting_to_zero branch from dcabb08 to 74d3b7f Compare December 14, 2022 21:40
Copy link
Member

@diemol diemol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @krmahadevan!

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@diemol diemol merged commit fad29a3 into SeleniumHQ:trunk Dec 14, 2022
@krmahadevan krmahadevan deleted the remote_content_length_setting_to_zero branch December 15, 2022 10:24
@krmahadevan
Copy link
Contributor Author

@diemol @pujagani - Please help re-open this defect. It looks like this is still NOT done.

Here's what I have as analysis:

  1. We got rid of all places wherein we are setting the content length explicitly to zero.
  2. When starting a container, we use the Docker container API with a POST message, but it has no body and so its content length now gets evaluated to zero.
  3. We are using the JDK client by default for all of our http client needs.
  4. We create a HttpRequest via org.openqa.selenium.remote.http.jdk.JdkHttpMessages#createRequest which internally calls org.openqa.selenium.remote.http.jdk.JdkHttpMessages#notChunkingBodyPublisher for a POST message.
  5. Since as per the docker api spec, there's no payload for this request, we end up getting evaluated to a content length of zero.
  6. This in turn triggers the validation check at the JDK HttpClient level saying
grid-node-docker-1    | java.lang.IllegalArgumentException: non-positive contentLength: 0
grid-node-docker-1    |         at java.net.http/java.net.http.HttpRequest$BodyPublishers.fromPublisher(HttpRequest.java:539)
grid-node-docker-1    |         at org.openqa.selenium.remote.http.jdk.JdkHttpMessages.notChunkingBodyPublisher(JdkHttpMessages.java:124)
grid-node-docker-1    |         at org.openqa.selenium.remote.http.jdk.JdkHttpMessages.createRequest(JdkHttpMessages.java:76)
grid-node-docker-1    |         at org.openqa.selenium.remote.http.jdk.JdkHttpClient.execute(JdkHttpClient.java:292)

Note:
We cannot set a payload also for this request, since when we do that, I hit an error as below

{
    "message": "starting container with non-empty request body was deprecated since API v1.22 and removed in v1.24"
}

with a 400 BAD REQUEST

I will raise a new PR for this in a few hours.

@krmahadevan
Copy link
Contributor Author

Here's the new PR #11445

@pujagani
Copy link
Contributor

Thank you for the details. I have reopened the associated GitHub issue as requested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Dynamic Grid setup fails when the docker images are missing locally
6 participants