vp340 commented on code in PR #3541:
URL: https://github.com/apache/cxf/pull/3541#discussion_r4189299157


##########
rt/features/logging/src/main/java/org/apache/cxf/ext/logging/LoggingOutputStream.java:
##########
@@ -71,4 +73,60 @@ public void writeCacheTo(StringBuilder out, String 
charsetName, long limit) thro
         super.writeCacheTo(out, charsetName, limit);
         skipFlushingFlowThroughStream = false;
     }
+
+
+    /**
+     * We override the write() methods in order to catch some error that would 
not
+     * close the CachedOutputStream (ex. IOException "Connection reset by 
peer".
+     * Causing ghost or delayed OUT log and possible memory-leak due to 
DelayedCachedOutputStreamCleaner
+     */
+    @Override
+    public void write(byte[] b) throws IOException {
+        try {
+            super.write(b);
+        } catch (RuntimeException | IOException ex) {
+            handleIoException();
+            throw ex;
+        }
+    }
+
+    @Override
+    public void write(byte[] b, int off, int len) throws IOException {
+        try {
+            super.write(b, off, len);
+        } catch (RuntimeException | IOException ex) {
+            handleIoException();
+            throw ex;
+        }
+    }
+
+    @Override
+    public void write(int b) throws IOException {
+        try {
+            super.write(b);
+        } catch (RuntimeException | IOException ex) {
+            handleIoException();
+            throw ex;
+        }
+    }
+
+    @Override
+    public void close() throws IOException {

Review Comment:
   I put the if (closed.compareAndSet(false, true)) in the close() method in 
order to close only once the Cos (and so log only once even if someone call 
again close() ).
   
   You want to add that control to prevent also the closure of 
getFlowThroughStream() (in that case we could do only if (!closed.get()) ) 
...or U want to put there instead the transition of closed from false -> true ? 
In this case can U explain me why (out of curiosity :)  )



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to