gnodet-bot commented on code in PR #28536:
URL: https://github.com/apache/camel/pull/28536#discussion_r4385852826


##########
components/camel-coap/src/main/java/org/apache/camel/coap/CoAPProducer.java:
##########
@@ -51,34 +52,36 @@ public void setClient(CoapClient client) {
     @Override
     public void process(Exchange exchange) throws Exception {
         initClient();
+        // doStop sets the client field to null, possibly while this request 
is in flight
+        CoapClient coapClient = client;

Review Comment:
   ⚠️ **JMM visibility gap:** The local-copy pattern is correct for NPE safety, 
but `client` is written by `doStop()` (`client = null`) without holding the 
lock, and read here without the lock. Without `volatile` on the field 
declaration, the JMM does not guarantee cross-thread visibility of `doStop()`'s 
null-write.
   
   Add `volatile` to the field:
   ```java
   private volatile CoapClient client;
   ```
   This guarantees that the null-write in `doStop()` is immediately visible to 
all threads reading `client`.



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to