diff --git a/source/vibe/core/task.d b/source/vibe/core/task.d index f394456..584dc5b 100644 --- a/source/vibe/core/task.d +++ b/source/vibe/core/task.d @@ -56,7 +56,7 @@ struct Task { auto fiber = () @trusted { return Fiber.getThis(); } (); if (!fiber) return Task.init; auto tfiber = cast(TaskFiber)fiber; - assert(tfiber !is null, "Invalid or null fiber used to construct Task handle."); + if (!tfiber) return Task.init; // FIXME: returning a non-.init handle for a finished task might break some layered logic return () @trusted { return Task(tfiber, tfiber.m_taskCounter); } (); } diff --git a/tests/vibe.core.core.1742.d b/tests/vibe.core.core.1742.d new file mode 100644 index 0000000..fd467e2 --- /dev/null +++ b/tests/vibe.core.core.1742.d @@ -0,0 +1,50 @@ +/+ dub.sdl: + name "tests" + description "Semaphore hang" + dependency "vibe-core" path="../" ++/ +module test; +import std.stdio; +import std.socket; +import std.datetime; +import std.functional; +import core.time; +import vibe.core.core; +import vibe.core.log; +import vibe.core.concurrency; +import vibe.core.connectionpool; + +class Conn {} + +void main() +{ + auto g = new Generator!int({ + auto t = runTask({}); + t.join(); + yield(2); + }); + assert(!g.empty); + assert(g.front == 2); + g.popFront(); + assert(g.empty); + + runTask({ + auto g2 = new Generator!int({ + auto t = runTask({}); + t.join(); + yield(1); + }); + assert(!g2.empty); + assert(g2.front == 1); + g2.popFront(); + assert(g2.empty); + exitEventLoop(); + }); + + setTimer(5.seconds, { + assert(false, "Test has hung."); + }); + + runApplication(); +} +