Skip to content

HADOOP-19996: Fix to drain the unread chunk terminator bytes from inp… - #8816

Open
vikaskr22 wants to merge 4 commits into
apache:trunkfrom
vikaskr22:HADOOP-19996
Open

vikaskr22 wants to merge 4 commits into
apache:trunkfrom
vikaskr22:HADOOP-19996

Conversation

@vikaskr22

Copy link
Copy Markdown
Contributor

…utStream to reuse the Connection

Description of PR

One performance issue was observed when migrated from JDK 8 to JDK 17. Considerable throughput fall was observed with Ranger-KMS service. On analysis, like by observing the sockets being created, It was found that KeepAlive cache was not working. TLS debug log (shared in JIRA) suggested that it is not trying to cache the connection while closing the stream.

When response size increases beyond the configured threshold ( In Tomcat, it's 8 KB ), Content-Type is set to "chunked" and ChunkedInputStream is used to read the response. No issues here.

Issue is occurring when complete JSON payload comes in one TLS record and chunk terminator bytes are coming in a separate TLS record. Jackson , that is being used to read the response, calls inputStream.close() as soon as it reads the entire payload, that is closing braces (}) and doesn't wait for the terminator chunk to arrive.

At this point, last chunk containing the terminator bytes has not yet arrived or has not yet been unwrapped, and ChunkedInputStream.close()---> hurry() tries to clean the unread bytes one last time without getting blocked. This operation is non-blocking by default. As a result, JVM was not able to clean the underlying inputStream and it can not be reused, hence connection is being destroyed. As a result, each call to ranger-KMS is doing a fresh new TLS handshaking.

FIX: As a fix, chunk terminator bytes or any unread bytes from response inputStream is being drained explicitly before calling close() on the underlying stream. To prevent Jackson from calling close() automatically just after reading the json payload, JsonParser.Feature.AUTO_CLOSE_SOURCE is being disabled. But please note that close() on underlying stream is being called from the finally block in both cases.

Further, logic to explicitly drain and close is being kept behind a flag which is set to "false" by default. It can be enabled by adding following property in the core-site.xml file :

Key :                 hadoop.security.kms.client.drain.response.unread.bytes
value:                true
Default value:   false

Cluster patched with this fix improved the throughput around three times and average latency also went down significantly.

How was this patch tested?

  • local mvn build passed.
  • Tested the change by patching the internal cluster with new hadoop-common jar.

Note: I had to skip few unrelated UTs for my local build as it was stuck for very long time, like org.apache.hadoop.security.TestDoAsEffectiveUser

For code changes:

  • Does the title of this PR start with the corresponding JIRA issue id (e.g. 'HADOOP-17799. Your PR title ...')? ==>YES
  • Object storage: Have the integration tests been executed and the endpoint
    declared according to the connector-specific documentation? Note: Automated CI
    testing doesn't cover all cases so manual testing with cloud storage is still
    required.
    ==> N/A
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0? ==> N/A
  • If applicable, have you updated the LICENSE, LICENSE-binary, NOTICE-binary files? ==? N/A

AI Tooling

If an AI tool was used:

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 7m 19s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 40m 0s trunk passed
+1 💚 compile 10m 16s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 10m 8s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 0m 58s trunk passed
+1 💚 mvnsite 1m 2s trunk passed
+1 💚 javadoc 0m 53s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 57s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 50s trunk passed
+1 💚 shadedclient 20m 38s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 43s the patch passed
+1 💚 compile 10m 9s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 10m 9s the patch passed
+1 💚 compile 10m 26s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 10m 26s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 55s the patch passed
+1 💚 mvnsite 1m 11s the patch passed
+1 💚 javadoc 0m 53s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 56s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 2m 4s the patch passed
+1 💚 shadedclient 19m 34s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 19m 8s hadoop-common in the patch passed.
+1 💚 asflicense 0m 48s The patch does not generate ASF License warnings.
161m 46s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/1/artifact/out/Dockerfile
GITHUB PR #8816
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets
uname Linux c83fab0ccb57 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / d49bd5c
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/1/testReport/
Max. process+thread count 1285 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/1/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@jojochuang jojochuang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

BTW I'm also curious if the problem is dependent on the fact that Ranger KMS is Tomcat based not Jetty based (Hadoop KMS). Just a hunch I want to bring up.

*/
public static final String DRAIN_RESPONSE_UNREAD_BYTES = CONFIG_PREFIX
+ "drain.response.unread.bytes";
public static final boolean DEFAULT_DRAIN_RESPONSE_UNREAD_BYTES = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

let's make it true by default, because we'll rely on this new behavior into the future.

@vikaskr22

Copy link
Copy Markdown
Contributor Author

BTW I'm also curious if the problem is dependent on the fact that Ranger KMS is Tomcat based not Jetty based (Hadoop KMS). Just a hunch I want to bring up.

@jojochuang , thanks for the review. let me add more details:

Hadoop-KMS and Ranger-KMS has same response write path: where it uses StreamEncoder as part of OutputStreamWriter to take care of encoding. This StreamEncoder has behaviour change in Java 8 & Java 17.

On server side, Jackson calls the close.
StreamEncoder.implClose() in Java 8 does write(bytes); & close();
In Java 17 it does write(bytes); then flush(); and then close(); That flush() propagates through Jersey's CommittingOutputStream and Tomcat's CoyoteOutputStream to OutputBuffer.doFlush(), which commits the response before its length is known → Transfer-Encoding: chunked, body in TLS record 1; the subsequent close() → ChunkedOutputFilter.end() writes 0\r\n\r\n as a separate socket write = separate TLS record 2.

On a Java 8 server nothing flushes early, OutputBuffer.close() sets Content-Length and the whole response is one record; the client uses KeepAliveStream, not ChunkedInputStream.

As per my analysis, same issue may happen with Hadoop-KMS as well but I have not yet verified this for Hadoop-KMS.

…re-default.

Default hadoop.security.kms.client.drain.response.unread.bytes to true so
JDK 17 clients reuse keep-alive connections to chunked KMS responses; add
core-default.xml description and opt-out guidance.

Co-authored-by: Cursor <cursoragent@cursor.com>
@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 26s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+0 🆗 xmllint 0m 0s xmllint was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 35m 53s trunk passed
+1 💚 compile 10m 11s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 10m 34s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 0m 54s trunk passed
+1 💚 mvnsite 1m 27s trunk passed
+1 💚 javadoc 0m 49s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 46s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 52s trunk passed
+1 💚 shadedclient 20m 55s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 49s the patch passed
+1 💚 compile 9m 35s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 9m 35s the patch passed
+1 💚 compile 11m 7s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 11m 7s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
+1 💚 checkstyle 0m 49s the patch passed
+1 💚 mvnsite 1m 7s the patch passed
+1 💚 javadoc 0m 45s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 49s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 52s the patch passed
+1 💚 shadedclient 21m 13s patch has no errors when building and testing our client artifacts.
_ Other Tests _
-1 ❌ unit 18m 40s /patch-unit-hadoop-common-project_hadoop-common.txt hadoop-common in the patch passed.
+1 💚 asflicense 0m 39s The patch does not generate ASF License warnings.
152m 6s
Reason Tests
Failed junit tests hadoop.conf.TestCommonConfigurationFields
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/2/artifact/out/Dockerfile
GITHUB PR #8816
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets xmllint
uname Linux 2f03aeaf723b 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / db9970f
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/2/testReport/
Max. process+thread count 1379 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/2/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

jojochuang and others added 2 commits October 13, 2026 14:56
…lic.

Fix TestCommonConfigurationFields by declaring the core-default property
alongside other KMS client keys and referencing it from KMSClientProvider.

Co-authored-by: Cursor <cursoragent@cursor.com>
Expose isChunkedHttpResponse for testing and cover IOUtils.drainAndClose
behavior including the 8 MiB read cap and HttpURLConnection error stream.

Co-authored-by: Cursor <cursoragent@cursor.com>
@jojochuang
jojochuang marked this pull request as ready for review October 13, 2026 22:08
@hadoop-yetus

Copy link
Copy Markdown

🎊 +1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 7m 31s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+0 🆗 xmllint 0m 0s xmllint was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
+1 💚 test4tests 0m 0s The patch appears to include 2 new or modified test files.
_ trunk Compile Tests _
+1 💚 mvninstall 28m 51s trunk passed
+1 💚 compile 9m 1s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 9m 10s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 0m 57s trunk passed
+1 💚 mvnsite 1m 7s trunk passed
+1 💚 javadoc 0m 59s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 54s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 46s trunk passed
+1 💚 shadedclient 17m 20s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 45s the patch passed
+1 💚 compile 8m 32s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 8m 32s the patch passed
+1 💚 compile 9m 8s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 9m 8s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 54s /results-checkstyle-hadoop-common-project_hadoop-common.txt hadoop-common-project/hadoop-common: The patch generated 1 new + 137 unchanged - 0 fixed = 138 total (was 137)
+1 💚 mvnsite 1m 16s the patch passed
+1 💚 javadoc 0m 54s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 53s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 57s the patch passed
+1 💚 shadedclient 16m 56s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 18m 22s hadoop-common in the patch passed.
+1 💚 asflicense 0m 48s The patch does not generate ASF License warnings.
139m 17s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/4/artifact/out/Dockerfile
GITHUB PR #8816
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets xmllint
uname Linux e8f2a3223d80 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 6aab885
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/4/testReport/
Max. process+thread count 1272 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/4/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

@hadoop-yetus

Copy link
Copy Markdown

💔 -1 overall

Vote Subsystem Runtime Logfile Comment
+0 🆗 reexec 0m 35s Docker mode activated.
_ Prechecks _
+1 💚 dupname 0m 0s No case conflicting files found.
+0 🆗 codespell 0m 0s codespell was not available.
+0 🆗 detsecrets 0m 0s detect-secrets was not available.
+0 🆗 xmllint 0m 0s xmllint was not available.
+1 💚 @author 0m 0s The patch does not contain any @author tags.
-1 ❌ test4tests 0m 0s The patch doesn't appear to include any new or modified tests. Please justify why no new tests are needed for this patch. Also please list what manual steps were performed to verify this patch.
_ trunk Compile Tests _
+1 💚 mvninstall 34m 47s trunk passed
+1 💚 compile 11m 11s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 compile 11m 4s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 checkstyle 0m 48s trunk passed
+1 💚 mvnsite 1m 8s trunk passed
+1 💚 javadoc 0m 50s trunk passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 50s trunk passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 1m 54s trunk passed
+1 💚 shadedclient 20m 20s branch has no errors when building and testing our client artifacts.
_ Patch Compile Tests _
+1 💚 mvninstall 0m 46s the patch passed
+1 💚 compile 10m 27s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javac 10m 27s the patch passed
+1 💚 compile 11m 16s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 javac 11m 16s the patch passed
+1 💚 blanks 0m 0s The patch has no blanks issues.
-0 ⚠️ checkstyle 0m 50s /results-checkstyle-hadoop-common-project_hadoop-common.txt hadoop-common-project/hadoop-common: The patch generated 1 new + 131 unchanged - 0 fixed = 132 total (was 131)
+1 💚 mvnsite 1m 12s the patch passed
+1 💚 javadoc 0m 57s the patch passed with JDK Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu
+1 💚 javadoc 0m 49s the patch passed with JDK Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
+1 💚 spotbugs 2m 3s the patch passed
+1 💚 shadedclient 21m 41s patch has no errors when building and testing our client artifacts.
_ Other Tests _
+1 💚 unit 18m 37s hadoop-common in the patch passed.
+1 💚 asflicense 0m 38s The patch does not generate ASF License warnings.
153m 50s
Subsystem Report/Notes
Docker ClientAPI=1.56 ServerAPI=1.56 base: https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/3/artifact/out/Dockerfile
GITHUB PR #8816
Optional Tests dupname asflicense compile javac javadoc mvninstall mvnsite unit shadedclient spotbugs checkstyle codespell detsecrets xmllint
uname Linux 1a34e8c958f7 5.15.0-190-generic #200-Ubuntu SMP Fri Aug 7 15:06:04 UTC 2026 x86_64 x86_64 x86_64 GNU/Linux
Build tool maven
Personality dev-support/bin/hadoop.sh
git revision trunk / 72358d4
Default Java Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Multi-JDK versions /usr/lib/jvm/java-21-openjdk-amd64:Ubuntu-21.0.12.1+1-1-24.04.4-Ubuntu /usr/lib/jvm/java-17-openjdk-amd64:Ubuntu-17.0.20.1+1-1-24.04-Ubuntu
Test Results https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/3/testReport/
Max. process+thread count 1286 (vs. ulimit of 10000)
modules C: hadoop-common-project/hadoop-common U: hadoop-common-project/hadoop-common
Console output https://ci-hadoop.apache.org/job/hadoop-multibranch/job/PR-8816/3/console
versions git=2.43.0 maven=3.9.15 spotbugs=4.9.7
Powered by Apache Yetus 0.14.1 https://yetus.apache.org

This message was automatically generated.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants