[ 
https://issues.apache.org/jira/browse/ARTEMIS-5689?focusedWorklogId=985656&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-985656
 ]

ASF GitHub Bot logged work on ARTEMIS-5689:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Oct/25 13:49
            Start Date: 03/Oct/25 13:49
    Worklog Time Spent: 10m 
      Work Description: tabish121 commented on code in PR #5950:
URL: https://github.com/apache/activemq-artemis/pull/5950#discussion_r2401992210


##########
artemis-protocols/artemis-amqp-protocol/src/main/java/org/apache/activemq/artemis/protocol/amqp/proton/AMQPTunneledCoreLargeMessageWriter.java:
##########
@@ -219,15 +219,14 @@ private boolean trySendDeliveryAnnotations(ByteBuf 
frameBuffer, NettyReadable fr
       for (; protonSender.getLocalState() != EndpointState.CLOSED && state == 
State.STREAMING_DELIVERY_ANNOTATIONS; ) {
          if (annotations != null && annotations.getValue() != null && 
!annotations.getValue().isEmpty()) {
             if (!connection.flowControl(this::resume)) {
-               break; // Resume will restart writing the headers section from 
where we left off.
+               break; // Resume will restart writing the delivery annotations 
section from where we left off.
             }
 
             final ByteBuf annotationsBuffer = 
getOrCreateDeliveryAnnotationsBuffer();
-            final int readSize = (int) Math.min(frameBuffer.writableBytes(), 
annotationsBuffer.readableBytes() - position);
+            final int readSize = Math.min(frameBuffer.writableBytes(), 
annotationsBuffer.readableBytes());
 
-            position += readSize;
-
-            annotationsBuffer.readBytes(frameBuffer, readSize);
+            
annotationsBuffer.readBytes(frameBuffer.internalNioBuffer(frameBuffer.writerIndex(),
 readSize));
+            frameBuffer.writerIndex(frameBuffer.writerIndex() + readSize);

Review Comment:
   It is effectively bypassing some of the onion peeling that happens in the 
netty buffer when doing the readBytes.  By leveraging the fact that we've 
allocated a fixed buffer which we control and knowing that we are safely within 
the boundaries we can leverage the internal NIO buffer to walk the path of an 
almost immediate bulk copy of bytes instead of peeling away the layers via 
readBytes and checking repeated for bounds and capacity there is a slight 
performance optimization. 
   
   This isn't necessary here for this fix but it does further align the logic 
used in the three states of writing the tunneled core message bytes which I 
felt was reasonable as it makes them all more consistent in their operation.





Issue Time Tracking
-------------------

    Worklog Id:     (was: 985656)
    Time Spent: 0.5h  (was: 20m)

> Tunneling Core Large Messages over broker connections can fail in some cases
> ----------------------------------------------------------------------------
>
>                 Key: ARTEMIS-5689
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-5689
>             Project: ActiveMQ Artemis
>          Issue Type: Bug
>          Components: AMQP
>    Affects Versions: 2.42.0
>            Reporter: Timothy A. Bish
>            Assignee: Timothy A. Bish
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 2.43.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> If the encoded delivery annotations or the Core encoded headers and 
> properties are larger than the frame buffer and need to be written in chunks 
> an error in the write loop can lead to an exception that fails the send of 
> that message.  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information, visit: https://activemq.apache.org/contact


Reply via email to