From a249bfa18e492a4317d739f7b9d839b796f005ba Mon Sep 17 00:00:00 2001 From: Nat Goodspeed Date: Mon, 11 Mar 2024 12:49:10 -0400 Subject: Make WaitQueue:_wait_waiters() skip dead coroutines. That is, skip coroutines that have gone dead since they decided to wait on Dequeue(). --- indra/newview/scripts/lua/WaitQueue.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/indra/newview/scripts/lua/WaitQueue.lua b/indra/newview/scripts/lua/WaitQueue.lua index e6adde0573..00766ccae7 100644 --- a/indra/newview/scripts/lua/WaitQueue.lua +++ b/indra/newview/scripts/lua/WaitQueue.lua @@ -37,14 +37,21 @@ function WaitQueue:_wake_waiters() -- or Dequeue() calls, recheck every time around to see if we must resume -- another waiting coroutine. while not self:IsEmpty() and #self._waiters > 0 do - -- pop the oldest waiting coroutine instead of the most recent, for - -- more-or-less round robin fairness + -- Pop the oldest waiting coroutine instead of the most recent, for + -- more-or-less round robin fairness. But skip any coroutines that + -- have gone dead in the meantime. local waiter = table.remove(self._waiters, 1) - -- don't pass the head item: let the resumed coroutine retrieve it - local ok, message = coroutine.resume(waiter) - -- if resuming that waiter encountered an error, don't swallow it - if not ok then - error(message) + while waiter and coroutine.status(waiter) ~= "suspended" do + waiter = table.remove(self._waiters, 1) + end + -- do we still have at least one waiting coroutine? + if waiter then + -- don't pass the head item: let the resumed coroutine retrieve it + local ok, message = coroutine.resume(waiter) + -- if resuming that waiter encountered an error, don't swallow it + if not ok then + error(message) + end end end end -- cgit v1.2.3