-
Notifications
You must be signed in to change notification settings - Fork 1.6k
LoggingProducerListener.onError() causes OutOfMemory exceptions for large messages #1898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
BTW, this pattern is widely copied in Kafka-related projects. For example, we can see completely the same in the KafkaMessageChannelBinder.DlqSender.sendToDlq() and have completely the same OOM error with large messages. |
A temporary workaround: This listener will be already used by createProducerMessageHandler:387, KafkaMessageChannelBinder |
Resolves spring-projects#1898 (comment) Large `byte[]` payloads could cause an OOM. **cherry-pick to 2.7.x, 2.6.x, 2.5.x**
Resolves #1898 (comment) Large `byte[]` payloads could cause an OOM. **cherry-pick to 2.7.x, 2.6.x, 2.5.x**
Resolves #1898 (comment) Large `byte[]` payloads could cause an OOM. **cherry-pick to 2.7.x, 2.6.x, 2.5.x**
Resolves #1898 (comment) Large `byte[]` payloads could cause an OOM. **cherry-pick to 2.7.x, 2.6.x, 2.5.x**
Resolves #1898 (comment) Large `byte[]` payloads could cause an OOM. **cherry-pick to 2.7.x, 2.6.x, 2.5.x** # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/support/LoggingProducerListener.java
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.
The text was updated successfully, but these errors were encountered: