[ 
https://issues.apache.org/jira/browse/LOG4J2-1874?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15999929#comment-15999929
 ] 

ASF GitHub Bot commented on LOG4J2-1874:
----------------------------------------

Github user remkop commented on the issue:

    https://github.com/apache/logging-log4j2/pull/71
  
    I'm not done reviewing yet but I found two issues:
    
    * StringBuilderEncoder used to have ThreadLocal<CharBuffer>, 
ThreadLocal<ByteBuffer> and ThreadLocal<CharsetEncoder> fields, now has one 
ThreadLocal<ThreadLocalState> field.  In the original code, the ThreadLocals 
only contains JDK classes, no custom (Log4j) classes. Where possible putting 
only JDK classes in ThreadLocals is preferable to avoid memory leaks in web 
containers: the Log4j classes may be loaded by a separate class loader which 
cannot be garbage collected if a thread pool threadlocal still has a reference 
to it. Can you revert this change?
    * The build consistently hangs in this core test: 
testCircularSuppressedExceptions(ThrowableProxyTest.java:391) 
    
    I tried this three times with the same result, but when building with 
master the build succeeds. I haven't investigated further yet. Full stack trace 
follows below (notice how it stops halfway a stack trace, as if a buffer is 
full...)
    
    ```
    23:13:06.369 [main] ERROR 
org.apache.logging.log4j.core.impl.ThrowableProxyTest - Error
    java.lang.Exception: null
            at 
org.apache.logging.log4j.core.impl.ThrowableProxyTest.testCircularSuppressedExceptions(ThrowableProxyTest.java:391)
 [test-classes/:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
~[?:1.8.0_131]
            at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[?:1.8.0_131]
            at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[?:1.8.0_131]
            at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_131]
            at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 [junit-4.12.jar:4.12]
            at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 [junit-4.12.jar:4.12]
            at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 [junit-4.12.jar:4.12]
            at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 [junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
[junit-4.12.jar:4.12]
            at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 [junit-4.12.jar:4.12]
            at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 [junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
            at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
[junit-4.12.jar:4.12]
            at org.junit.runners.Suite.runChild(Suite.java:128) 
[junit-4.12.jar:4.12]
            at org.junit.runners.Suite.runChild(Suite.java:27) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
            at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
            at org.junit.runners.ParentRunner.run(ParentRunner.java:363) 
[junit-4.12.jar:4.12]
            at 
org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55) 
[surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
 [surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:107)
 [surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:83)
 [surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
 [surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:161)
 [surefire-junit47-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
 [surefire-booter-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
 [surefire-booter-2.19.1.jar:2.19.1]
            at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) 
[surefire-booter-2.19.1.jar:2.19.1]
            Suppressed: java.lang.Exception
                    at 
org.apache.logging.log4j.core.impl.ThrowableProxyTest.testCircularSuppressedExceptions(ThrowableProxyTest.java:392)
 [test-classes/:?]
                    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native 
Method) ~[?:1.8.0_131]
                    at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[?:1.8.0_131]
                    at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[?:1.8.0_131]
                    at java.lang.reflect.Method.invoke(Method.java:498) 
~[?:1.8.0_131]
                    at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 [junit-4.12.jar:4.12]
                    at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 [junit-4.12.jar:4.12]
                    at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 [junit-4.12.jar:4.12]
                    at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 [junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 [junit-4.12.jar:4.12]
                    at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 [junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
                    at org.junit.runners.Suite.runChild(Suite.java:128) 
[junit-4.12.jar:4.12]
                    at org.junit.runners.Suite.runChild(Suite.java:27) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
                    at 
org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
                    at 
org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55) 
[surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
 [surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:107)
 [surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:83)
 [surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:75)
 [surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:161)
 [surefire-junit47-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:290)
 [surefire-booter-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:242)
 [surefire-booter-2.19.1.jar:2.19.1]
                    at 
org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:121) 
[surefire-booter-2.19.1.jar:2.19.1]
                    Suppressed: java.lang.Exception
                            at 
org.apache.logging.log4j.core.impl.ThrowableProxyTest.testCircularSuppressedExceptions(ThrowableProxyTest.java:391)
 [test-classes/:?]
                            at 
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_131]
                            at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[?:1.8.0_131]
                            at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[?:1.8.0_131]
                            at java.lang.reflect.Method.invoke(Method.java:498) 
~[?:1.8.0_131]
                            at 
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
 [junit-4.12.jar:4.12]
                            at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
 [junit-4.12.jar:4.12]
                            at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
 [junit-4.12.jar:4.12]
                            at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
 [junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
 [junit-4.12.jar:4.12]
                            at 
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
 [junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
                            at org.junit.runners.Suite.runChild(Suite.java:128) 
[junit-4.12.jar:4.12]
                            at org.junit.runners.Suite.runChild(Suite.java:27) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$3.run(ParentRunner.java:290) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.access$000(ParentRunner.java:58) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) 
[junit-4.12.jar:4.12]
                            at 
org.junit.runners.ParentRunner.run(ParentRunner.java:363) [junit-4.12.jar:4.12]
                            at 
org.apache.maven.surefire.junitcore.JUnitCore.run(JUnitCore.java:55) 
[surefire-junit47-2.19.1.jar:2.19.1]
                            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:137)
 [surefire-junit47-2.19.1.jar:2.19.1]
                            at 
org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUni
    ```


> Add ByteBufferDestionation.write(ByteBuffer) and write(byte[], int, int) 
> methods and call them from TextEncoderHelper whenever possible
> ---------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-1874
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1874
>             Project: Log4j 2
>          Issue Type: Improvement
>            Reporter: Roman Leventov
>            Assignee: Remko Popma
>
> Existing ByteBufferDestination API: getByteBuffer() and drain() is designed 
> so that synchronization couldn't be avoided. This doesn't allow to implement 
> LOG4J2-928.
> Github PR: https://github.com/apache/logging-log4j2/pull/71
> Added methods: write(ByteBuffer data) and write(byte[] data, int offset, int 
> length) are designed so that they should care about synchronization 
> themselves, internally, if needed. They should also synchronize with possible 
> concurrent users of the synchronized getByteBuffer() + drain() API. 
> Nevertheless, it allows for ByteBufferDestination implementations to 
> implement write() methods without lock-free.
> TextEncoderHelper (hence StringBuilderEncoder, which delegates it's logic to 
> TextEncoderHelper) is changed so that it calls ByteBufferDestination.write() 
> whenever possible.  There is an expectation that most of encoded events fit 
> the thread-local buffers, and write() could be called instead of writing to 
> destination.getByteBuffer() with synchronization.
> The PR also includes a sanity improvement: uses ByteBuffer.arrayOffset() at 
> some places.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Reply via email to