lhotari opened a new pull request #10278:
URL: https://github.com/apache/pulsar/pull/10278


   ### Motivation
   
   Client's producer epoch handling was added #5571 . An issue has been 
reported as #9792 where this solution hasn't worked.
   When looking at the code, it seems that there's a concurrency issue. 
   The epoc field is incremented in the timer thread, but read in another 
thread. There is no synchronization / volatile field in place.
   In Java, updating double or long values isn't thread safe.
   Explained in [JLS 
17.7](https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.7)
   > For the purposes of the Java programming language memory model, a single 
write to a non-volatile long or double value is treated as two separate writes: 
one to each 32-bit half. This can result in a situation where a thread sees the 
first 32 bits of a 64-bit value from one write, and the second 32 bits from 
another write.
   
   ### Modifications
   
   - use volatile field for epoch
   - use AtomicLongFieldUpdater for incrementing the value (although it would 
be fine to omit it when a single timer thread is updating the value. However 
this method isn't a final method and subclasses can override the reconnectLater 
method.)


-- 
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:
[email protected]


Reply via email to