Skip to content

LoggingProducerListener.onError() causes OutOfMemory exceptions for large messages #1898

@krocodl

Description

@krocodl

For spring-kafka 2.5.2.RELEASE

The problem code fragment:

.append(" and payload='") .append(toDisplayString(ObjectUtils.nullSafeToString(record.value()), this.maxContentLogged))

For example, it the service tries to handle 20Mb message and the parameter "spring.cloud.stream.kafka.binder.configuration.max.request.size" is not increased accordingly, we expect to receive an exception about the "max.request.size" value.

But instead of this, ObjectUtils.nullSafeToString(record.value()) attempts to transform byte[] inside the String, where each byte is represented by about 5 bytes - something like ", 123".
As a result, we receive OOM, where the StringJoiner object occupies about half of the memory.

So, it is necessary to pass the "this.maxContentLogged" parameter inside the function "ObjectUtils.nullSafeToString" too, in order to prevent dumping the full byte array.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions