Skip to content
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

fix: do not log complete stream causing OOM #2258

Merged
merged 1 commit into from
Feb 6, 2025
Merged

Conversation

Thom-x
Copy link
Contributor

@Thom-x Thom-x commented Feb 6, 2025

Log the hashCode instead of toString to avoid dumping all the file content in memory and in log because of https://github.com/apache/cxf/blob/main/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java#L423
This cause OOM on our app.

Exception in thread "DelayedCachedOutputStreamCleaner" java.lang.OutOfMemoryError: Java heap space
at java.base/java.util.Arrays.copyOf(Arrays.java:3541)                                                                     
at java.base/java.lang.AbstractStringBuilder.ensureCapacityInternal(AbstractStringBuilder.java:242)                        
at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:744)                                        
at java.base/java.lang.StringBuilder.append(StringBuilder.java:233)                                                        
at org.apache.cxf.io.CachedOutputStream.writeCacheTo(CachedOutputStream.java:404)                                          
at org.apache.cxf.io.CachedOutputStream.writeCacheTo(CachedOutputStream.java:382)                                          
at org.apache.cxf.io.CachedOutputStream.toString(CachedOutputStream.java:428)                                              
at java.base/java.lang.StringConcatHelper.stringOf(StringConcatHelper.java:467)                                            
at java.base/java.lang.StringConcatHelper.simpleConcat(StringConcatHelper.java:422)                                        
at java.base/java.lang.invoke.DirectMethodHandle$Holder.invokeStatic(DirectMethodHandle$Holder)                            
at java.base/java.lang.invoke.LambdaForm$MH/0x00007fffa0010800.invoke(LambdaForm$MH)                                       
at java.base/java.lang.invoke.Invokers$Holder.linkToTargetMethod(Invokers$Holder)                                          
at org.apache.cxf.io.DelayedCachedOutputStreamCleaner$DelayedCleanerImpl.clean(DelayedCachedOutputStreamCleaner.java:122)  
at org.apache.cxf.io.DelayedCachedOutputStreamCleaner$DelayedCleanerImpl.clean(DelayedCachedOutputStreamCleaner.java:102)  
at org.apache.cxf.io.DelayedCachedOutputStreamCleaner$DelayedCleanerImpl$1.run(DelayedCachedOutputStreamCleaner.java:83)   
at java.base/java.util.TimerThread.mainLoop(Timer.java:566)                                                                
at java.base/java.util.TimerThread.run(Timer.java:516) 

Log the hashCode instead of toString to avoid dumping all the file content in memory and in log because of https://github.com/apache/cxf/blob/main/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java#L423
This cause OOM on our app.
@Thom-x Thom-x changed the title fix: do not log complete stream. fix: do not log complete stream causing OOM Feb 6, 2025
@@ -119,7 +119,7 @@ private void clean(Collection<DelayedCloseable> closeables) {
final DelayedCloseable next = iterator.next();
try {
iterator.remove();
LOG.warning("Unclosed (leaked?) stream detected: " + next.closeable);
LOG.warning("Unclosed (leaked?) stream detected: " + next.closeable.hashCode());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @Thom-x , this was certainly not expected ...

@reta reta merged commit 1c1d687 into apache:main Feb 6, 2025
4 checks passed
reta pushed a commit that referenced this pull request Feb 6, 2025
Log the hashCode instead of toString to avoid dumping all the file content in memory and in log because of https://github.com/apache/cxf/blob/main/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java#L423
This cause OOM on our app.

(cherry picked from commit 1c1d687)
reta pushed a commit that referenced this pull request Feb 6, 2025
Log the hashCode instead of toString to avoid dumping all the file content in memory and in log because of https://github.com/apache/cxf/blob/main/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java#L423
This cause OOM on our app.

(cherry picked from commit 1c1d687)
(cherry picked from commit 24bb53c)
reta pushed a commit that referenced this pull request Feb 7, 2025
Log the hashCode instead of toString to avoid dumping all the file content in memory and in log because of https://github.com/apache/cxf/blob/main/core/src/main/java/org/apache/cxf/io/CachedOutputStream.java#L423
This cause OOM on our app.

(cherry picked from commit 1c1d687)
(cherry picked from commit 24bb53c)
(cherry picked from commit 20cfa99)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants