| Ticket UUID: | 3104471 | ||
| Title: | "command returned bad code: 2" in bgerror | ||
| Type: | Bug | Created on: | 2010-11-07 05:34:29 |
| Submitter: | andygoth | Assigned to: | dgp |
| Subsystem: | 01. Notifier | Severity: | |
| Priority: | 5 Medium | Last modified: | 2010-12-19 10:13:36 |
| Status: | Open | Closed by: | |
| Resolution: | None | Closed on: | |
| Version: | obsolete: 8.6b1.1 | ||
| Description: | ||||
I really don't know what to make of this one. I'll just give you the facts and let you decide what the heck is going on. :^)
Earlier today I updated to the latest CVS HEAD (ChangeLog revision 1.5291), compiled, and installed. I confirmed that the infinite loop on [append]ing to empty string is fixed. But I then spotted a new problem while working on Wibble. When the client closes its connection, this triggers the "finally" code at the end of [process]. On the "catch {chan close $socket}" line, I get a bgerror popup box saying: "Error: command returned bad code: 2". This didn't happen before I did the CVS update. I should mention that I [source]d wibble.tcl into tkcon; also, I have not changed versions of tkcon. I used gdb to confirm that this error is being generated by TclDefaultBgErrorHandlerObjCmd() in tclEvent.c.
I replaced the "finally" code with:
puts a
if {[llength [chan names $socket]]} {
puts b
chan close $socket
puts c
}
puts d
This caused "a" and "d" to be printed, and the error details are:
command returned bad code: 2
couldn't open "c:/msys/local/lib/tclIndex": no such file or directory
while executing
"open [file join $dir tclIndex]"
which is completely mystifying. This code appears in neither Wibble nor tkcon. It's in [auto_load_index] in library/init.tcl, *inside* a [catch] block!
Changing the "finally" code to:
puts a
catch {chan close $socket}
puts b
causes "a", "b", and "d" to be printed, and I get this error detail:
command returned bad code: 2
can not find channel named "sock252"
while executing
"chan close $socket"
What is that catch doing, anyway?
| ||||
| User Comments: | ||||
kennykb added on 2010-11-08 07:04:06:
Hmmm. From the symptoms, it appears as if something inside the [try] block is doing a 'return -code return' or 'return -level' all the way out to the event loop, causing the "invalid return code 2" (2 is TCL_RETURN). Since return code 2 isn't an error, ::errorInfo doesn't get set, so it contains whatever error information was pertinent to the last catch - in this case the one in init.tcl. So the stack trace is bogus, but there's no other stack information to report (the return was successful, it's just that it's asking the event loop to return, and the event loop has nowhere to return *to.* It's arguable that errorInfo should be suppressed in this case, or perhaps whatever is reporting the invalid return code should gen something up to report what callout it had made that returned inappropriately. In any case, by manipulating the try/catch/finally, you've found what call it was: what remains is to find out why it's doing [return] when it isn't in a proc. I'm forwarding this one to dgp, because TclDefaultBgErrorCmd appears to be his, and he may have more insight into how to get a less confusing message out of all this. andygoth added on 2010-11-08 07:56:37:
[wibble::getline] calls [return -level [info level]] on [chan eof $chan], which is exactly the code path that's giving me trouble. The intention is to terminate the coroutine. [return -level [info level]] allows the finally's to trigger, which is what I need. [rename [info coroutine] ""; yield] bypasses finally, so I can't use it.
The coroutine is being invoked by [chan event]. More accurately, [chan event] schedules it to be invoked when the channel is readable.
The problem goes away if I modify [listen] to change this line:
chan event $socket readable [namespace code $socket]
to this wordier version that inserts a stack level between the coroutine and the event loop:
chan event $socket readable [list apply [list {} [list $socket] [namespace current]]]
However, I don't think this is the solution. This appears to be a regression in Tcl, because my code worked without complaint in previous CVS revisions of Tcl 8.6.
See http://wiki.tcl.tk/_/revision?N=27377.txt&V=11 for the version of Wibble I'm using. Also, thanks for looking into this.
andygoth added on 2010-12-19 10:13:36:
To reproduce with the latest version of Wibble (http://wiki.tcl.tk/_/revision?N=27377.txt&V=17), change the lambda body in [resume] from {$coro $args} to {tailcall $coro $args}. This results in "command returned bad code: 0" when the client closes the connection.
| ||||
