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


##########
src/iocore/cache/CacheVC.cc:
##########
@@ -853,8 +853,11 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* 
e ATS_UNUSED */)
         }
       }
       earliest_key = key;
-      int result1  = 
_action.continuation->handleEvent(CACHE_EVENT_SCAN_OBJECT, vector.get(i));
-      switch (result1) {
+      auto result1 = _action.call_back(CACHE_EVENT_SCAN_OBJECT, vector.get(i));
+      if (!result1) {
+        goto Lcancel;
+      }
+      switch (*result1) {

Review Comment:
   `result1` is non-descriptive, and in this updated form it also implicitly 
conveys an optional/nullable return contract from `_action.call_back`. Renaming 
it to something like `scan_result` / `handler_result` would make the control 
flow (especially the `!result1` cancel branch and `switch (*result1)`) easier 
to understand and less error-prone to maintain.



##########
src/iocore/cache/CacheVC.cc:
##########
@@ -973,11 +976,17 @@ CacheVC::scanOpenWrite(int /* event ATS_UNUSED */, Event 
* /* e ATS_UNUSED */)
 {
   Dbg(dbg_ctl_cache_scan_truss, "inside %p:scanOpenWrite", this);
   cancel_trigger();
+  if (_action.cancelled) {
+    return free_CacheVC(this);
+  }
   // get volume lock
   if (writer_lock_retry > SCAN_WRITER_LOCK_MAX_RETRY) {
-    int r = 
_action.continuation->handleEvent(CACHE_EVENT_SCAN_OPERATION_BLOCKED, nullptr);
+    auto r = _action.call_back(CACHE_EVENT_SCAN_OPERATION_BLOCKED, nullptr);
     Dbg(dbg_ctl_cache_scan, "still haven't got the writer lock, asking 
user..");
-    switch (r) {
+    if (!r || _action.cancelled) {
+      return free_CacheVC(this);
+    }
+    switch (*r) {

Review Comment:
   Using `auto` for `r` obscures the fact that `_action.call_back(...)` can 
return an empty/nullable value that must be checked before dereference. 
Consider making the type explicit (or using a single-statement initializer in 
the `if`/`switch` pattern) to document the cancellation/empty-return contract 
at the call site and reduce the chance of future edits accidentally 
dereferencing without the guard.



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