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


##########
src/iocore/net/NetHandler.cc:
##########
@@ -113,9 +126,92 @@ NetHandler::stopCop(NetEvent *ne)
   ink_release_assert(ne->nh == this);
 
   open_list.remove(ne);
-  cop_list.remove(ne);
   remove_from_keep_alive_queue(ne);
   remove_from_active_queue(ne);
+  timer_wheel.cancel(ne);
+}
+
+ink_hrtime
+NetHandler::_earliest_deadline(NetEvent *ne) const
+{
+  ink_hrtime const inactivity = ne->next_inactivity_timeout_at;
+  ink_hrtime const activity   = ne->next_activity_timeout_at;

Review Comment:
   These deadline fields are non-atomic, but foreign threads can update them 
through `set_enabled()` and the timeout setters. `Fire::deadline_of()` now 
reads them before acquiring the connection mutex, and `process_handoffs()` also 
reads them through this helper without that lock. Owner-only wheel updates 
therefore do not prevent a C++ data race on the deadlines. Synchronize deadline 
reads and writes too, using nonblocking lock-and-retry handling or synchronized 
deadline storage; deferring only the wheel linkage is insufficient.



##########
src/iocore/net/NetEvent.cc:
##########
@@ -0,0 +1,61 @@
+/** @file
+
+  NetEvent timer helpers: owner-thread-safe timer rearm and default inactivity 
deadline rebasing.
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "iocore/net/NetEvent.h"
+#include "iocore/net/NetHandler.h"
+
+void
+NetEvent::rearm_timer()
+{
+  NetHandler *const h = nh;
+
+  if (h == nullptr) {
+    return;
+  }
+  // The owning thread touches its wheel without holding the NetHandler mutex,
+  // so the mutex does not protect it and a foreign thread must not take it.
+  if (h->thread == this_ethread()) {
+    h->rearm_timer(this);
+  } else {
+    h->defer_rearm(this);
+  }
+}
+
+void
+NetEvent::rebase_default_inactivity_deadline(ink_hrtime previous_in)
+{
+  if (!use_default_inactivity_timeout || inactivity_timeout_in != 0 || 
next_inactivity_timeout_at == 0) {
+    return; // the deadline did not come from the default
+  }

Review Comment:
   Installing a positive default on an enabled connection with no explicit 
timeout and no existing deadline returns here without scheduling anything. For 
example, this can happen when a per-remap override replaces a zero default. If 
no more traffic arrives, neither `netActivity()` nor `set_enabled()` repairs 
it, so the connection never gets the fallback timeout that the old sweep would 
arm. Handle this unarmed state as well as rebasing existing default-derived 
deadlines.



##########
src/iocore/net/UnixNetVConnection.cc:
##########
@@ -1292,13 +1339,14 @@ UnixNetVConnection::set_inactivity_timeout(ink_hrtime 
timeout_in)
   Dbg(dbg_ctl_socket, "Set inactive timeout=%" PRId64 ", for NetVC=%p", 
timeout_in, this);
   inactivity_timeout_in      = timeout_in;
   next_inactivity_timeout_at = (timeout_in > 0) ? ink_get_hrtime() + 
inactivity_timeout_in : 0;
+  rearm_timer();

Review Comment:
   With I/O already enabled, `set_inactivity_timeout(0)` clears the deadline 
and cancels the wheel entry even when a positive default timeout exists. An 
idle connection gets no further `set_enabled()` or `netActivity()` call, so the 
default may never fire. This is reachable through zero-valued transaction 
inactivity timeouts in `HttpSM`. Apply the default when clearing the explicit 
timeout on an enabled connection, as the old sweep did.



##########
src/iocore/net/UnixNetVConnection.cc:
##########
@@ -1052,7 +1093,8 @@ UnixNetVConnection::mainEvent(int event, Event * /* e 
ATS_UNUSED */)
   }
 
   *signal_timeout_at = 0;
-  writer_cont        = write.vio.cont;
+  rearm_timer();

Review Comment:
   If either VIO mutex is contended, `mainEvent()` returns `EVENT_CONT` at 
lines 1065–1068 before reaching this rearm. The wheel has already removed the 
connection, and `InactivityCop::Fire` ignores the callback result, so both 
remaining deadlines can stay unscheduled indefinitely. Add `rearm_timer()` 
before that lock-failure return so both timeout types are retried, as they were 
by the old sweep.



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