apache/incubator-seata · error · RuntimeException

Deflater compress error

Error message

Deflater compress error

What it means

DeflaterUtil.compress wraps IOException from the in-memory deflation loop into RuntimeException('Deflater compress error'). Since output goes to a ByteArrayOutputStream, an IOException is unexpected and usually masks a deeper failure (native zlib error from malformed input state, or memory pressure) surfacing through the loop that calls Deflater.deflate().

Source

Thrown at compressor/seata-compressor-deflater/src/main/java/org/apache/seata/compressor/deflater/DeflaterUtil.java:47

    public static byte[] compress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        int length = 0;
        Deflater deflater = new Deflater();
        deflater.setInput(bytes);
        deflater.finish();
        byte[] outputBytes = new byte[BUFFER_SIZE];
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            while (!deflater.finished()) {
                length = deflater.deflate(outputBytes);
                bos.write(outputBytes, 0, length);
            }
            deflater.end();
            return bos.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("Deflater compress error", e);
        }
    }

    public static byte[] decompress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        int length = 0;
        Inflater inflater = new Inflater();
        inflater.setInput(bytes);
        byte[] outputBytes = new byte[BUFFER_SIZE];
        try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
            while (!inflater.finished()) {
                length = inflater.inflate(outputBytes);
                if (length == 0) {
                    break;
                }
                bos.write(outputBytes, 0, length);

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Read the attached cause; if it is memory-related, increase heap or reduce payload size (page the batch).
  2. Cap the size of payloads you compress, or choose compressor: none for oversized messages if your protocol allows.
  3. Run on a standard JDK image to rule out broken zlib natives.
  4. Catch RuntimeException at the boundary and fall back to uncompressed/alternate compressor.

Example fix

// before
 byte[] packed = DeflaterUtil.compress(raw);

// after
 byte[] packed;
try {
    packed = DeflaterUtil.compress(raw);
} catch (RuntimeException e) {
    log.error("deflater compress failed, sending uncompressed", e);
    packed = raw;
 }
Defensive patterns

Strategy: try-catch

Try / catch

try {
    return DeflaterUtil.compress(bytes);
} catch (RuntimeException e) {
    log.error("deflater compress failed", e.getCause());
    return bytes; // or rethrow if compression is mandatory
}

Prevention

When it happens

Trigger: DeflaterUtil.compress(bytes) where the ByteArrayOutputStream write or deflater loop throws — extremely large inputs causing allocation failures inside the loop, or a corrupted JDK/native zlib environment; direct invocation with adversarial byte arrays.

Common situations: Enabling deflater compression for oversized undo logs or batch RPC messages in memory-constrained containers; broken zlib natives on exotic base images; rarely, JVM bugs around Deflater after native memory exhaustion.

Related errors


AI-assisted analysis of apache/incubator-seata@e01f97c6db (2026-08-14). Data as JSON: /api/errors/f7a2707f07dad27d. Report an issue: GitHub.