Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling task is running, but scheduled to be resumed!? #58

Closed
TETYYS opened this issue Feb 16, 2018 · 5 comments
Closed

Calling task is running, but scheduled to be resumed!? #58

TETYYS opened this issue Feb 16, 2018 · 5 comments
Labels

Comments

@TETYYS
Copy link

TETYYS commented Feb 16, 2018

I'm facing a problem while trying to create a new task inside a task (with setTimer inside runWorkerTaskH) , it throws an assert error Calling task is running, but scheduled to be resumed!? on

??:? _d_assert_msg [0xa6045bae]
??:? nothrow @trusted void vibe.core.task.TaskScheduler.switchTo(vibe.core.task.Task, std.typecons.Flag!("defer").Flag) [0xf9ad23b3]
??:? nothrow @trusted vibe.core.task.Task vibe.core.core.runTask_internal!(vibe.core.core.runTask!(void function(void delegate() nothrow @safe, vibe.core.core.Timer) @safe*, void delegate() nothrow @safe, vibe.core.core.Timer).runTask(void function(void delegate() nothrow @safe, vibe.core.core.Timer) @safe*, ref void delegate() nothrow @safe, ref vibe.core.core.Timer).__lambda5).runTask_internal() [0xf9ab786e]
??:? nothrow @safe vibe.core.task.Task vibe.core.core.runTask!(void function(void delegate() nothrow @safe, vibe.core.core.Timer) @safe*, void delegate() nothrow @safe, vibe.core.core.Timer).runTask(void function(void delegate() nothrow @safe, vibe.core.core.Timer) @safe*, ref void delegate() nothrow @safe, ref vibe.core.core.Timer) [0xf9ab7637]
??:? nothrow @safe vibe.core.core.Timer vibe.core.core.createTimer(void delegate() nothrow @safe) [0xf9ab6ac5]
??:? nothrow @safe vibe.core.core.Timer vibe.core.core.setTimer(core.time.Duration, void delegate() nothrow @safe, bool) [0xf9ab681f]
??:? nothrow vibe.core.core.Timer vibe.core.core.setTimer(core.time.Duration, void delegate(), bool) [0xf9ab68e6]
??:? nothrow @trusted void myCallingFunction(shared(myObject), bool) [0xf999a55e]
??:? void vibe.core.taskpool.TaskPool.runTaskH!(void function(shared(myObject), bool) nothrow @trusted*, shared(myObject), bool).runTaskH(void function(shared(myObject), bool) nothrow @trusted*, ref shared(myObject), ref bool).taskFun(vibe.core.task.Task, void function(shared(myObject), bool) nothrow @trusted*, shared(myObject), bool) [0xf992d5f1]
??:? void vibe.core.task.TaskFuncInfo.set!(void function(vibe.core.task.Task, void function(shared(myObject), bool) nothrow @trusted*, shared(myObject), bool)*, vibe.core.task.Task, void function(shared(myObject), bool) nothrow @trusted*, shared(myObject), bool).set(ref void function(vibe.core.task.Task, void function(shared(myObject), bool) nothrow @trusted*, shared(myObject), bool)*, ref vibe.core.task.Task, ref void function(shared(myObject), bool) nothrow @trusted*, ref shared(myObject), ref bool).callDelegate(ref vibe.core.task.TaskFuncInfo) [0xf992f4c4]
??:? void vibe.core.task.TaskFuncInfo.call() [0xf9ad1c5d]
??:? nothrow void vibe.core.task.TaskFiber.run() [0xf9ad1275]
??:? void core.thread.Fiber.run() [0xa604a65b]
??:? fiber_entryPoint [0xa6049a26]
??:? [0xffffffff]

Any idea what causes this? It happens randomly when creating a lot of worker tasks which call setTimer
and when all worker tasks are queued, but always when they are running, at some point.

@TETYYS
Copy link
Author

TETYYS commented Feb 16, 2018

rel #37 ? @s-ludwig mentioned if there any uncaught exceptions in the task, but the whole myCallingFunction is a nothrow

@s-ludwig
Copy link
Member

Could it be that there was an earlier assertion error, or something silimar, such as a range error, happening before the mentioned error? That should have terminated the application immediately, unless VibeDebugCatchAll is defined, but just making sure before dismissing this thesis.

Otherwise, do you see a chance for extracting a reproduction case from this? I could try to just fire worker tasks and create timers inside to see whether that is enough to trigger it, but otherwise it looks hard to diagnose, since this is very likely caused by something that has happened in a previous task that ran on the same fiber.

@TETYYS
Copy link
Author

TETYYS commented Feb 17, 2018

Narrowed it down to a shared ManualEvent (createSharedManualEvent), this code throws the error every time:

import vibe.vibe;
import std.datetime;

shared ManualEvent ev;

shared static this()
{
	ev = createSharedManualEvent();
}

static void worker()
{
	ev.wait();
	ev.emit();
	setTimer(dur!"seconds"(1), {
		logInfo(":)");
	});
}

void main()
{
	runTask({
		foreach (x; 0 .. 3000) {
			runWorkerTaskH(&worker);
		}
	});

	setTimer(dur!"msecs"(50), {
		ev.emit();
	});

	runApplication();
}

@s-ludwig
Copy link
Member

Thanks a lot! I'll try to find some time to debug this next week.

@s-ludwig s-ludwig added the bug label Feb 22, 2018
s-ludwig added a commit that referenced this issue Feb 22, 2018
s-ludwig added a commit that referenced this issue Feb 22, 2018
Previously the task was only removed if switchTo was called from another task. Now it also gets removed when switchTo (e.g. due to a runTask() call) gets called form outside of a task.
s-ludwig added a commit that referenced this issue Feb 22, 2018
s-ludwig added a commit that referenced this issue Feb 22, 2018
Previously the task was only removed if switchTo was called from another task. Now it also gets removed when switchTo (e.g. due to a runTask() call) gets called form outside of a task.
s-ludwig added a commit that referenced this issue Feb 22, 2018
s-ludwig added a commit that referenced this issue Feb 22, 2018
Previously the task was only removed if switchTo was called from another task. Now it also gets removed when switchTo (e.g. due to a runTask() call) gets called form outside of a task.
s-ludwig added a commit that referenced this issue Feb 23, 2018
s-ludwig added a commit that referenced this issue Feb 23, 2018
Previously the task was only removed if switchTo was called from another task. Now it also gets removed when switchTo (e.g. due to a runTask() call) gets called form outside of a task.
@TETYYS
Copy link
Author

TETYYS commented Feb 24, 2018

very nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants