codelipenghui opened a new pull request #5748: Fix NPE and release already 
released ByteBuf in batch message container
URL: https://github.com/apache/pulsar/pull/5748
 
 
   Fixes #5746 #5747
   
   ### Motivation
   
   Fix NPE and release an already released ByteBuf when publish an oversize 
message.
   
   Here is error log:
   ```
   io.netty.util.IllegalReferenceCountException: refCnt: 0, decrement: 1
        at 
io.netty.util.internal.ReferenceCountUpdater.toLiveRealRefCnt(ReferenceCountUpdater.java:74)
 ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
        at 
io.netty.util.internal.ReferenceCountUpdater.release(ReferenceCountUpdater.java:138)
 ~[netty-common-4.1.43.Final.jar:4.1.43.Final]
        at 
io.netty.buffer.AbstractReferenceCountedByteBuf.release(AbstractReferenceCountedByteBuf.java:100)
 ~[netty-buffer-4.1.43.Final.jar:4.1.43.Final]
        at io.netty.util.ReferenceCountUtil.release(ReferenceCountUtil.java:88) 
~[netty-common-4.1.43.Final.jar:4.1.43.Final]
        at 
io.netty.util.ReferenceCountUtil.safeRelease(ReferenceCountUtil.java:113) 
[netty-common-4.1.43.Final.jar:4.1.43.Final]
        at 
org.apache.pulsar.client.impl.BatchMessageKeyBasedContainer$KeyedBatch.discard(BatchMessageKeyBasedContainer.java:244)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.BatchMessageKeyBasedContainer.createOpSendMsg(BatchMessageKeyBasedContainer.java:125)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.BatchMessageKeyBasedContainer.createOpSendMsgs(BatchMessageKeyBasedContainer.java:145)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerImpl.batchMessageAndSend(ProducerImpl.java:1426)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerImpl.triggerFlush(ProducerImpl.java:1411) 
[classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:112) 
[classes/:?]
        at 
org.apache.pulsar.client.impl.TypedMessageBuilderImpl.send(TypedMessageBuilderImpl.java:89)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:63) 
[classes/:?]
        at 
org.apache.pulsar.broker.service.BatchMessageTest.testSendOverSizeMessage(BatchMessageTest.java:875)
 [test-classes/:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
~[?:1.8.0_201]
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[?:1.8.0_201]
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[?:1.8.0_201]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
        at 
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
 [testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:583) 
[testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) 
[testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) 
[testng-6.14.3.jar:?]
        at 
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
 [testng-6.14.3.jar:?]
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 
[testng-6.14.3.jar:?]
        at org.testng.TestRunner.privateRun(TestRunner.java:648) 
[testng-6.14.3.jar:?]
        at org.testng.TestRunner.run(TestRunner.java:505) [testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.run(SuiteRunner.java:364) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuites(TestNG.java:1049) [testng-6.14.3.jar:?]
        at org.testng.TestNG.run(TestNG.java:1017) [testng-6.14.3.jar:?]
        at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73) 
[testng-plugin.jar:?]
        at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123) 
[testng-plugin.jar:?]
   
   
   
   16:19:13.850 [main:org.apache.pulsar.client.impl.ProducerImpl@1439] WARN  
org.apache.pulsar.client.impl.ProducerImpl - 
[persistent://prop/ns-abc/testSendOverSizeMessage-623833fc-d9f7-4b28-aead-27955928fae9]
 [test-0-0] error while create opSendMsg by batch message container
   java.lang.NullPointerException: null
        at 
org.apache.pulsar.client.impl.ProducerImpl.releaseSemaphoreForSendOp(ProducerImpl.java:858)
 ~[classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerImpl.processOpSendMsg(ProducerImpl.java:1477)
 ~[classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerImpl.batchMessageAndSend(ProducerImpl.java:1432)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerImpl.triggerFlush(ProducerImpl.java:1411) 
[classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:112) 
[classes/:?]
        at 
org.apache.pulsar.client.impl.TypedMessageBuilderImpl.send(TypedMessageBuilderImpl.java:89)
 [classes/:?]
        at 
org.apache.pulsar.client.impl.ProducerBase.send(ProducerBase.java:63) 
[classes/:?]
        at 
org.apache.pulsar.broker.service.BatchMessageTest.testSendOverSizeMessage(BatchMessageTest.java:875)
 [test-classes/:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
~[?:1.8.0_201]
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
~[?:1.8.0_201]
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 ~[?:1.8.0_201]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_201]
        at 
org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
 [testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeMethod(Invoker.java:583) 
[testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719) 
[testng-6.14.3.jar:?]
        at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989) 
[testng-6.14.3.jar:?]
        at 
org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
 [testng-6.14.3.jar:?]
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109) 
[testng-6.14.3.jar:?]
        at org.testng.TestRunner.privateRun(TestRunner.java:648) 
[testng-6.14.3.jar:?]
        at org.testng.TestRunner.run(TestRunner.java:505) [testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:455) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunner.run(SuiteRunner.java:364) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) 
[testng-6.14.3.jar:?]
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1137) 
[testng-6.14.3.jar:?]
        at org.testng.TestNG.runSuites(TestNG.java:1049) [testng-6.14.3.jar:?]
        at org.testng.TestNG.run(TestNG.java:1017) [testng-6.14.3.jar:?]
        at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:73) 
[testng-plugin.jar:?]
        at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123) 
[testng-plugin.jar:?]
   ```
   
   ### Modifications
   
   Add check for processOpSendMsg, if the op is null, just return.
   Don't release the batchedMessageMetadataAndPayload since it is already 
released in getCompressedBatchMetadataAndPayload() method.
   
   ### Verifying this change
   
   The exists unit tests can cover this change
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (no)
     - The schema: (no)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: (no)
     - Anything that affects deployment: (no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (no)
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to