-
Notifications
You must be signed in to change notification settings - Fork 236
fix: Replaced classLoader in DriverJar #1811
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
base: main
Are you sure you want to change the base?
Conversation
Since we could not reproduce it before, can you add a test that demonstrates the bug and that the fix actually resolves it? |
Ok, I will try it |
Hi, @yury-s However, when running the same code inside a Docker container, the following issue occurs: Thread.currentThread().getContextClassLoader() returns null
This causes failures when attempting to load resources (e.g., getResource(...)). After investigation, I found that switching to: this.getClass().getClassLoader()
resolves the issue both locally and in the Docker container. To help reproduce and compare the issue, I’ve created a sample repo here: You can build the Docker image using the included Dockerfile and test the endpoints: http://localhost:8080/playwright?url=https://google.com (uses Thread.currentThread().getContextClassLoader()) -> You can check the error log in the console when accessing this endpoint. http://localhost:8080/playwright2?url=https://google.com (uses this.getClass().getClassLoader()) This is my first open source contribution, so I’d appreciate any feedback or suggestions! Thank you 🙇 |
The test has quite some logic which make it not obvious wether the problem is in the test or in Playwright. Can you try to reduce it to a minimal example and drop all unrelated logic? Ideally it would be converted into one of the Playwright tests. If the setup requires a custom environment (e.g. spring framework), you can put it in its own project. There is already a bunch of custom tests in the tools/ directory, particularly this one. You could convert yours into a similar one. We also run Docker tests for our container on GitHub Actions: https://github.com/microsoft/playwright-java/actions/workflows/test_docker.yml. If the test requires Docker environment, we can run the new test inside the Playwright Docker image as part of the same test suite. Would that work? Given that this PR change the core part of the project, I'd really like to have a test that covers it. |
Sure, I’ll go ahead with that. |
Hi, @yury-s The test consists of two approaches: To verify the behavior in the Docker environment, I followed the test_docker.yml setup: CONTAINER_ID="$(docker run --rm -e CI --ipc=host -v $(pwd):/root/playwright --name playwright-docker-test -d -t playwright-java:localbuild-noble /bin/bash)" java -jar /mypath/playwright/tools/test-spring-classloader/target/test-spring-classloader-1.50.0-SNAPSHOT.jar As a result, the first approach failed with an error, while the second one succeeded, confirming the issue. |
@microsoft-github-policy-service agree |
@yury-s
In some environments, such as Docker or the sbt plugin, accessing the ContextClassLoader is not reliable.
Because the driver package is bundled within the JAR, class.getClassLoader() is used instead.
issues: #1447 , #1803