JDK-8303937 : Corrupted heap dumps due to missing retries for os::write()
  • Type: Bug
  • Component: core-svc
  • Sub-Component: tools
  • Affected Version: 11.0.14,15,16,17,18,19,20,21
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2023-03-10
  • Updated: 2023-09-19
  • Resolved: 2023-03-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 11 JDK 17 JDK 20 JDK 21
11.0.20Fixed 17.0.8Fixed 20.0.2Fixed 21 b14Fixed
Related Reports
Relates :  
Relates :  
Relates :  
Relates :  
Description
After JDK-8237354, we noticed heap dumps could become corrupted.

The root cause is in FileWriter::write_buf() in heapDumperCompression.cpp, for n = os::write(_fd, buf, (uint) size); n could be > 0 but smaller than size. In this case, there should be a loop to retry os::write() for the remaining bytes in buf. There was such a loop in DumpWriter::write_internal() before JDK-8237354.

This problem is well documented in the man page for write(): https://man7.org/linux/man-pages/man2/write.2.html#RETURN_VALUE.

In our case, we see the corruption frequently because we support dumping heap to a socket or pipe.
Comments
Fix request [11u] Resolved trivial merge conflict in https://github.com/openjdk/jdk11u-dev/pull/1801. Fixes a real bug that causes heap dump corruption. The bug was introduced into 11.0.14u in https://github.com/openjdk/jdk11u-dev/commit/1868c15d4e5d03895a4a07edacd864021dfbac57. Low risk. All tier1 tests passed in Github pre-submit checks. In addition, manually ran: - test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java - test/jdk/sun/tools/jmap/BasicJMapTest.java and both passed.
14-03-2023

Fix request [17u] Resolved trivial merge conflict in https://github.com/openjdk/jdk17u-dev/pull/1201. Fixes a real bug that causes heap dump corruption. Low risk. All tier1 tests passed in Github pre-submit checks. In addition, manually ran: - test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java - test/jdk/sun/tools/jmap/BasicJMapTest.java and both passed.
14-03-2023

Fix request [20u] Clean backport and no conflict. Fixes a real bug that causes heap dump corruption. Low risk. All tier1 tests passed in Github pre-submit checks. In addition, manually ran: - test/jdk/com/sun/management/HotSpotDiagnosticMXBean/DumpHeap.java - test/jdk/sun/tools/jmap/BasicJMapTest.java and both passed.
14-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk11u-dev/pull/1801 Date: 2023-03-10 21:57:34 +0000
10-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk17u-dev/pull/1201 Date: 2023-03-10 21:06:18 +0000
10-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk20u/pull/18 Date: 2023-03-10 20:36:56 +0000
10-03-2023

Changeset: bf16b5b9 Author: Man Cao <manc@openjdk.org> Date: 2023-03-10 18:14:09 +0000 URL: https://git.openjdk.org/jdk/commit/bf16b5b9880eb89b283006db090dce4346aa877b
10-03-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/12966 Date: 2023-03-10 02:13:22 +0000
10-03-2023