Copilot commented on code in PR #14005:
URL: https://github.com/apache/trafficserver/pull/14005#discussion_r4494955163
##########
src/iocore/eventsystem/ConfigProcessor.cc:
##########
@@ -216,6 +229,100 @@ ConfigProcessor::release(unsigned int id, ConfigInfo
*info)
}
}
+struct ConfigProcessor::ThreadPins {
+ struct Pin {
+ uint64_t generation = 0;
+ std::shared_ptr<ConfigInfo> config;
+ bool listed = false;
+ };
+
+ std::array<Pin, MAX_CONFIGS> pins;
+ // Slots this thread has pinned at some point, so the per-loop sweep skips
the rest.
+ static_assert(MAX_CONFIGS <= 256, "slot indices in used are stored as
uint8_t");
+ std::array<uint8_t, MAX_CONFIGS> used{};
+ size_t used_count = 0;
+};
+
+std::shared_ptr<ConfigInfo> &
+ConfigProcessor::_pin(unsigned int id)
+{
+ unsigned int const idx = id - 1;
+ auto &pin = _thread_pins->pins[idx];
+ uint64_t const generation =
_generations[idx].value.load(std::memory_order_acquire);
+
+ if (!pin.config || pin.generation != generation) {
+ if (!pin.listed) {
+ pin.listed = true;
+ _thread_pins->used[_thread_pins->used_count++] =
static_cast<uint8_t>(idx);
+ }
+ // A scope in the current event may still use the replaced configuration,
but set() keeps its own
+ // reference for the release timeout, so dropping the pin here cannot free
it.
+ pin.config.reset();
Review Comment:
A second pinned or leased read of the same slot can reset its owning pin
while an earlier `scoped_config` still holds a raw pointer. If the handler
outlasts the replacement's release timeout, this can free the configuration
before that scope finishes, despite obeying the documented handler lifetime.
Retain displaced pins until `release_stale_pins()` runs between events, and add
coverage for refreshing a slot after the processor's delayed reference has
expired.
--
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]