Tcl Source Code

View Ticket
Login
2026-10-17
08:47 • Ticket [cc592ec70d] vwait not NRE-enabled: C stack busy status still Open wi... artifact: f62e981572 user: serhiy.storchaka
08:47
Fix [cc592ec70d]: a second yieldto after one that failed with "C stack busy" panicked with "tailcall... check-in: d10cadf3ca user: serhiy.storchaka tags: core-8-6-branch
2021-06-23
13:01 • Closed ticket [f9800d52bd]: vwait is not NRE-enabled, and yieldto cannot find th... artifact: 0e22c12b3b user: jan.nijtmans
2021-06-21
14:54 • Open ticket [f9800d52bd]. artifact: 824dd98358 user: jan.nijtmans
05:44 • Ticket [5106fddd44] failure to yieldto is not the same thing as not calling yiel... artifact: 6c43e1b849 user: pooryorick
2021-06-20
23:11 • Pending ticket [f9800d52bd]: vwait is not NRE-enabled, and yieldto cannot find t... artifact: 25e0e0bbb4 user: pooryorick
23:10 • Ticket [f9800d52bd]: 3 changes artifact: a5883ef8c0 user: pooryorick
23:10 • Ticket [f9800d52bd]: 3 changes artifact: f539153892 user: pooryorick
22:47
Fix for [f9800d52bd61f240], vwait is not NRE-enabled, and yieldto cannot find the right splicing spo... check-in: eb50e83ee1 user: pooryorick tags: bug-f9800d52bd61f240
18:28 • Ticket [f9800d52bd] vwait is not NRE-enabled, and yieldto cannot find the right ... artifact: e067049ad3 user: pooryorick
07:45 • Ticket [f9800d52bd]: 3 changes artifact: 76cd3d8c7d user: dkf
06:41 • Ticket [f9800d52bd]: 3 changes artifact: 6ae4458216 user: pooryorick
2021-06-19
21:36 • Ticket [f9800d52bd]: 3 changes artifact: 543bd21881 user: pooryorick
21:36 • New ticket [f9800d52bd]. artifact: 2debc3b81e user: pooryorick

Ticket UUID: f9800d52bd61f240938dbd3c3c6364c8a6184194
Title: vwait is not NRE-enabled, and yieldto cannot find the right splicing spot
Type: Bug Created on: 2021-06-19 21:36:06
Submitter: pooryorick Assigned to: pooryorick
Subsystem: - New Builtin Commands Severity: Critical
Priority: 5 Medium Last modified: 2021-06-23 13:01:38
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2021-06-23 13:01:38
Version:
Description:

At least as of [07f12cf7209a23fa3], core-8-branch, the script below aborts. The trouble begins with the C stack being busy because c2 has been called from with vwait, which is not yet NRE-enabled. Although the error message talks about tailcall, it is really about yieldto, which calls TclSetTailcall.

proc main_coro {} {
	set done [catch {
		coroutine c1 p0 
		yieldto c1
		coroutine c2 p1
		after 0 [list [namespace which c2]]
		vwait forever 
	} cres copts]
}

proc p0 {} {
	yield
	::tailcall main
}

proc p1 {} {
	yield
	set this [info coroutine]
	set script [list ::yieldto [list $this]]
	yieldto try $script on error {cres copt} "
		puts \[list uh-oh \$cres]
		[list $this]
	"
	set script [list ::yieldto $this]
	yieldto ::try $script
}


coroutine main main_coro

Output:

uh-oh {cannot yield: C stack busy}
tailcall cannot find the right splicing spot: should not happen!
Aborted (core dumped)

User Comments:
pooryorick added on 2021-06-20 06:41:00:

sebres noted this issue in [cc592ec70de012df].


dkf added on 2021-06-20 07:45:06:

Well, this shouldn't crash. It probably should be an error though; I can't comprehend any way to make vwait itself be anything other than NRE-unaware.


pooryorick added on 2021-06-20 18:28:46:

Here is a slightly smaller script to reproduce the issue:

proc p0 {} {
	yield
	yieldto c1
	after 0 c2 
	vwait forever
}

proc p1 {} {
	yield
	tailcall c0
}

proc p2 {} {
	yield
	after 0 [list [info coroutine]]
	yieldto try {yieldto c1} on error {} c1
	yieldto try [list yieldto c1]
}
coroutine c0 p0
coroutine c1 p1
coroutine c2 p2
after 0 [list [namespace which c0]]
vwait forever


pooryorick added on 2021-06-20 23:10:13:

The problem is that TclSetTailcall splices the command to be yielded to into the right place, but when TclNRCoroutineActivateCallback decides the C stack is busy, it doesn't go back and undo the splice. At that point, the splicing spot is already taken and any other attempt to yieldto produces the error, "tailcall cannot find the right splicing spot: should not happen!". From here on out, that command that hasn't been unspliced behaves like a tailcall: When the coroutine ends that command takes its place. Tailcall itself doesn't have the same problem as yieldto because tailcall uses a slightly different mechanism to register the tailcall. The solution is to undo that splice of the pending command if yieldto can't proceed.


pooryorick added on 2021-06-20 23:10:45:

Fixed in [c75d4c3be05d5e91].


jan.nijtmans added on 2021-06-21 14:54:08:

'Fix' reverted from core-8-branch, because it broke the build.

See: https://github.com/tcltk/tcl/runs/2872891537?check_suite_focus=true

coroutine.test
Test file error: cannot yield: C stack busy
    while executing
"yieldto c1"
    ("try" body line 1)
    invoked from within
"c2"
    ("after" script)
cannot yield: C stack busy
    while executing
"yieldto c1"
    ("try" body line 1)
    ("after" script)


jan.nijtmans added on 2021-06-23 13:01:38:

Merged (again) to core-8-branch (and trunk). Appears to work now.

Thanks for the fix, and the updated testcase!