From bf16b5b9880eb89b283006db090dce4346aa877b Mon Sep 17 00:00:00 2001 From: Man Cao Date: Fri, 10 Mar 2023 18:14:09 +0000 Subject: [PATCH] 8303937: Corrupted heap dumps due to missing retries for os::write() Reviewed-by: cjplummer, dholmes --- src/hotspot/share/services/heapDumperCompression.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/services/heapDumperCompression.cpp b/src/hotspot/share/services/heapDumperCompression.cpp index c9ace619097..bd2ca18c61d 100644 --- a/src/hotspot/share/services/heapDumperCompression.cpp +++ b/src/hotspot/share/services/heapDumperCompression.cpp @@ -55,10 +55,14 @@ char const* FileWriter::write_buf(char* buf, ssize_t size) { assert(_fd >= 0, "Must be open"); assert(size > 0, "Must write at least one byte"); - ssize_t n = os::write(_fd, buf, (uint) size); + while (size > 0) { + ssize_t n = os::write(_fd, buf, (uint) size); + if (n <= 0) { + return os::strerror(errno); + } - if (n <= 0) { - return os::strerror(errno); + buf += n; + size -= n; } return nullptr;