apache/incubator-seata · error · RuntimeException

gzip compress error

Error message

gzip compress error

What it means

GzipUtil.compress wraps IOException from GZIPOutputStream into RuntimeException('gzip compress error'). The stream writes to an in-memory ByteArrayOutputStream, so normal IO failures are impossible; the exception indicates broken gzip state — most often the JDK's deflater failed (native zlib issue, input too large for available memory) or the stream was used inconsistently (finish/flush after close).

Source

Thrown at compressor/seata-compressor-gzip/src/main/java/org/apache/seata/compressor/gzip/GzipUtil.java:42

public class GzipUtil {

    private GzipUtil() {}

    private static final int BUFFER_SIZE = 8192;

    public static byte[] compress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (GZIPOutputStream gzip = new GZIPOutputStream(out)) {
            gzip.write(bytes);
            gzip.flush();
            gzip.finish();
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("gzip compress error", e);
        }
    }

    public static byte[] decompress(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes is null");
        }

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        try (GZIPInputStream gunzip = new GZIPInputStream(new ByteArrayInputStream(bytes))) {
            byte[] buffer = new byte[BUFFER_SIZE];
            int n;
            while ((n = gunzip.read(buffer)) > -1) {
                out.write(buffer, 0, n);
            }
            return out.toByteArray();
        } catch (IOException e) {
            throw new RuntimeException("gzip decompress error", e);

View on GitHub (pinned to e01f97c6db)

Solutions

  1. Inspect the cause; for memory pressure, increase heap/native memory or reduce payload size (batch/paginate).
  2. Switch to compressor: none for messages above a size threshold, or pick a cheaper compressor (identity/deflater) for huge payloads.
  3. Verify on a stock JDK image to rule out native zlib problems.
  4. Catch RuntimeException at the boundary and degrade to uncompressed transfer if the protocol permits.

Example fix

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

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

Strategy: try-catch

Try / catch

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

Prevention

When it happens

Trigger: GzipUtil.compress(bytes) where gzip.write/flush/finish throws — huge payloads exhausting native/memory limits, or a damaged JDK/zlib environment; direct calls with pathological inputs.

Common situations: gzip chosen as undo-log/transport compressor for very large transactions; containers with low memory limits; base images with a broken zlib; rarely, classpath-shipped JDK internals conflicting with the runtime JDK.

Related errors


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