[java] Fix saving docker logs to a file#17218
Conversation
it's nonsense because GET requests don't have BODY (while "Content-Type" describes the request body). Apparently, the intention was to specify expected response type. Then http header "Accept" should be used instead. But anyway, docker ignores it, and always responds in "application/vnd.docker.multiplexed-stream" format (or "application/octet-stream" for older docker versions).
There was a bug that method "stop" was called twice (first time regular, and the second time - from some "cache expiration listener" in Grid). The second call could not get container logs anymore, and overrode the logs file with empty content.
Review Summary by QodoFix Docker logs parsing and storage in Grid
WalkthroughsDescription• Fix Docker logs parsing to correctly handle multiplexed stream format • Store logs as stream instead of loading entire content into memory • Remove unnecessary HTTP Content-Type header from GET request • Prevent duplicate log file writes when container stops twice • Fix NPE when TZ environment variable is missing File Changes1. java/src/org/openqa/selenium/docker/Container.java
|
Code Review by Qodo
1. ContainerLogs constructor signature changed
|
instead of reading the whole response into memory, just copy the InputStream from "/logs" docker response to "selenium-server.log" file. NB! It's still incorrect solution because docker "/logs" response has a special format "application/vnd.docker.multiplexed-stream", and we need to parse it accordingly. Namely, it contains few "technical" bytes in the beginning of every log line.
This response has content type "application/vnd.docker.raw-stream". It's almost a plain text, but we need to skip few "technical" bytes in the beginning of every log line. This is how log lines in the resulting file "selenium-server.log" look like: * Before: `�??????g2026-03-13 09:30:55,398 INFO Included extra file` * After: `2026-03-13 09:54:06,477 INFO Included extra file `
96dedf7 to
9ff3dde
Compare
🔗 Related Issues
Fixes #17209
💥 What does this PR do?
Fixes the way how docker response "/logs" is parsed and saved to a file.
🔄 Types of changes
Result
This is how log lines in the resulting file "selenium-server.log" look like:
�??????g2026-03-13 09:30:55,398 INFO Included extra file2026-03-13 09:54:06,477 INFO Included extra file