From 9b2aa13ef44e587eb6dfbabfb0c02d0c3f8cd097 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Sun, 26 Aug 2018 13:03:14 +0200 Subject: [PATCH] Fix possible infinite loop in TaskScheduler.process. Fixes a discrepancy in TaskFiberQueue between empty and length, which causes process() to never return, thus processing events without timeout indefinitely. --- source/vibe/core/task.d | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/source/vibe/core/task.d b/source/vibe/core/task.d index 0813743..22ad957 100644 --- a/source/vibe/core/task.d +++ b/source/vibe/core/task.d @@ -962,9 +962,29 @@ private struct TaskFiberQueue { task.m_queue = null; task.m_prev = null; task.m_next = null; + length--; } } +unittest { + auto f1 = new TaskFiber; + auto f2 = new TaskFiber; + + TaskFiberQueue q; + assert(q.empty && q.length == 0); + q.insertFront(f1); + assert(!q.empty && q.length == 1); + q.insertFront(f2); + assert(!q.empty && q.length == 2); + q.popFront(); + assert(!q.empty && q.length == 1); + q.popFront(); + assert(q.empty && q.length == 0); + q.insertFront(f1); + q.remove(f1); + assert(q.empty && q.length == 0); +} + private struct FLSInfo { void function(void[], size_t) fct; size_t offset;