Copilot commented on code in PR #13098:
URL: https://github.com/apache/trafficserver/pull/13098#discussion_r3114016949


##########
src/iocore/net/SSLCertLookup.cc:
##########
@@ -249,7 +250,7 @@ SSLCertContext::operator=(SSLCertContext const &other)
     this->userconfig = other.userconfig;
     this->keyblock   = other.keyblock;
     this->ctx_type   = other.ctx_type;
-    std::lock_guard<std::mutex> lock(other.ctx_mutex);
+    std::shared_lock lock(other.ctx_mutex);

Review Comment:
   `SSLCertContext::operator=` writes `this->ctx` without taking 
`this->ctx_mutex`. Since `getCtx()`/`setCtx()` use `ctx_mutex` to synchronize 
access to `ctx`, this assignment can cause a data race if the object is 
assigned while other threads are calling `getCtx()`/`setCtx()` (e.g., during 
reload). Consider taking an exclusive lock on `this->ctx_mutex` while updating 
`ctx` (and avoid deadlock by locking `other.ctx_mutex` and `this->ctx_mutex` 
with a consistent ordering / `std::lock`).
   ```suggestion
       std::shared_lock other_lock(other.ctx_mutex, std::defer_lock);
       std::unique_lock this_lock(this->ctx_mutex, std::defer_lock);
   
       std::lock(other_lock, this_lock);
   ```



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