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

ASF subversion and git services commented on AMQ-9658:
------------------------------------------------------

Commit d9e89f4b5fdb21da54e47588988161accd0fc9d6 in activemq's branch 
refs/heads/main from Christopher L. Shannon
[ https://gitbox.apache.org/repos/asf?p=activemq.git;h=d9e89f4b5f ]

AMQ-9658 - Properly increment transport receive counter (#1389)

Switch to using an AtomicInteger for tracking bytes received in a
TcpTransport. This makes incrementing the counter an atomic operation.
Previously a volatile int was used and incrementing volatiles is not
atomic because it's a 3 step process of read, update, set.

This also makes a small fix to ensure that the full initialization
buffer will always be entirely read and processed when using
the auto+nio+ssl transport. Previous the code assumed only the first
command was stored in the initialization buffer but technically more
bytes could exist for a future command (even if unlikely with the
current Java implementation).


> TcpTransport volatile receiveCounter is not incremented atomically
> ------------------------------------------------------------------
>
>                 Key: AMQ-9658
>                 URL: https://issues.apache.org/jira/browse/AMQ-9658
>             Project: ActiveMQ Classic
>          Issue Type: Bug
>    Affects Versions: 5.18.6, 6.1.5
>            Reporter: Christopher L. Shannon
>            Assignee: Christopher L. Shannon
>            Priority: Minor
>             Fix For: 6.2.0, 5.19.0, 6.1.6
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> incrementing volatile integers is not an atomic operation because the 
> previous value must first be read, then incremented, and reset so it is a 
> multi step process. I noticed in the TCP transport code that the receive 
> counter was a volatile integer and not being incremented properly.  This 
> counter is should only be incremented in the same thread anyways (it can be 
> read by other threads like inactivity monitor) so it may not technically be 
> an issue in practice  but it still should be handled properly.
> The fix is to switch to an AtomicInteger. I also noticed a minor improvement 
> to make to to the NIOSSLtransport init code that is only used for the 
> auto+nio+ssl transport that I will fix as well. (ensure the full 
> initialization buffer will always be entirely read and processed when using 
> the auto+nio+ssl transport. ) 



--
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