prestodb/presto · warning · UncheckedIOException

Failed to close ByteArrayOutputStream

Error message

Failed to close ByteArrayOutputStream

What it means

AvroRowEncoder.close() wraps any IOException thrown while closing the underlying ByteArrayOutputStream into an UncheckedIOException. ByteArrayOutputStream.close() is documented as a no-op and practically never throws, so this guard exists purely to satisfy the Closeable contract of the RowEncoder interface and shield callers from checked exceptions.

Source

Thrown at presto-kafka/src/main/java/com/facebook/presto/kafka/encoder/avro/AvroRowEncoder.java:157

            dataFileWriter.append(record);
            dataFileWriter.close();

            resetColumnIndex(); // reset currentColumnIndex to prepare for next row
            return byteArrayOutputStream.toByteArray();
        }
        catch (IOException e) {
            throw new UncheckedIOException("Failed to append record", e);
        }
    }

    @Override
    public void close()
    {
        try {
            byteArrayOutputStream.close();
        }
        catch (IOException e) {
            throw new UncheckedIOException("Failed to close ByteArrayOutputStream", e);
        }
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. No action needed: the underlying ByteArrayOutputStream.close() is a no-op and cannot realistically fail.
  2. If it ever surfaces, inspect the wrapped IOException cause for an unusual OutputStream subclass or agent-decorated stream and fix that resource.
  3. Upgrade Presto, since this defensive wrapper could be simplified/silenced in newer versions.
Defensive patterns

Strategy: try-catch

Try / catch

// close() already wraps into UncheckedIOException; only needed if calling stream.close() directly
try {
    encoder.close();
} catch (UncheckedIOException e) {
    log.warn("Failed to close AvroRowEncoder: %s", e.getMessage(), e);
}

Prevention

When it happens

Trigger: Calling close() on an AvroRowEncoder after encoding rows; the try/catch fires only if byteArrayOutputStream.close() throws an IOException, which for ByteArrayOutputStream effectively never happens.

Common situations: Teardown of a Kafka record encoder at the end of a query page; try-with-resources on the encoder; almost always seen only as an impossible defensive branch or during JVM-level I/O errors.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/8050619b584af2ea. Report an issue: GitHub.