Ivan Sadikov created SPARK-62364:
------------------------------------
Summary: PartiallySerializedBlock.finishWritingToStream leaks the
compression stream when writing the rest of the block fails
Key: SPARK-62364
URL: https://issues.apache.org/jira/browse/SPARK-62364
Project: Spark
Issue Type: Bug
Components: Spark Core
Affects Versions: 5.0.0
Reporter: Ivan Sadikov
When \{{MemoryStore.putIteratorAsBytes}} cannot unroll a block fully, it
returns a \{{PartiallySerializedBlock}} that owns the still-open serialization
stream (wrapped by \{{SerializerManager.wrapForCompression}}). For storage
levels that use disk, such as \{{MEMORY_AND_DISK_SER}},
\{{BlockManager.doPutIterator}} then calls
\{{PartiallySerializedBlock.finishWritingToStream}} to write the unrolled bytes
and the rest of the input iterator to the disk store.
{\{finishWritingToStream}} has no failure handling. If the disk write,
\{{rest.next()}}, or \{{serializationStream.writeObject}} throws, the
serialization stream is never closed. The task completion listener registered
by \{{PartiallySerializedBlock}} only disposes of the unrolled buffer, and
\{{consumed}} is already true, so \{{discard()}} is never called either.
With the default zstd codec the compressed stream is a
\{{ZstdOutputStreamNoFinalizer}}, whose native compression context and buffers
are released only by \{{close()}}, not by GC. Every task that fails this way
leaks one native context on the executor. The task fails but the executor
survives, so the leak grows across retries and on long-running executors,
outside the JVM heap limits. Common triggers are an exception from the RDD's
input iterator, a \{{NotSerializableException}} or \{{KryoException}} while
serializing the remaining values, and an I/O error from the disk write.
This is the same leak as SPARK-62048, which fixes the paths inside
\{{putIteratorAsBytes}} (an exception while unrolling, and a task kill after a
partial unroll); it does not cover \{{finishWritingToStream}}.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]