Tcl Source Code

View Ticket
Login
Ticket UUID: 39bb9b3ebb5ea83c4037980750b2c7a8929ff624
Title: deleting a coroutine bypasses try..finally handlers
Type: Bug Created on: 2015-11-11 04:29:36
Submitter: aspect Assigned to: nobody
Subsystem: 60. NRE and coroutines Severity: Minor
Priority: 5 Medium Last modified: 2015-11-11 04:29:36
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.4
Description:
When a coroutine is deleted by [rename] or through deletion of its namespace,
finally handlers are not invoked:


% coroutine foo try yield finally {puts ok}
% rename foo {}

% namespace eval foo { coroutine foo try yield finally {puts ok} }
% namespace delete foo

Delete traces do fire, providing a sort of workaround:

% coroutine foo apply {{{t 0}} {
    trace add variable t unset {puts ok; list}
    yield
}}
% rename foo {}
ok

Arguably this might not be a bug, but it renders [try .. finally] unreliable
for resource deletion in the presence of coroutines.


Miguel's previous comments from the chat:

2015-08-09:

<aspect> % coroutine c try yield finally {puts ok}; rename c {}   ;# no output
<aspect> that makes deleting coroutines .. problematic
<aspect> delete traces fire though:
<aspect> % coroutine c apply {{{t 0}} {trace add variable t unset {puts ok;
         list}; yield}}; rename c {}   ;# emits "ok"

<miguel> what is problemtic about deleting coroutines?
<miguel> they self-delete when they return; you can delete them as normal
         commands otherwise - even from within
<miguel> ohhh ... the finally never executed, right ... will look into it
<miguel> (possibly a problem also for [interp cancel], as they share the
         mechanism iirc)
<miguel> it is a fundamental problem - the classic invincible-force vs
         unmovable-object: "cancel everything no matter what" vs "before
         canceling you HAVE to do this one thing (which may require infinite
         resources)"
<miguel> (at least in the [interp cancel] version)
<miguel> % try {interp cancel -unwind} finally {puts ok}
<miguel> eval unwound
 * miguel finds this not trivial at all
<miguel> the problem is that the finally clause WILL get executed RIGHT AFTER 
         the try clause finishes - which happens to be NEVER in aspect's setup


2015-11-11:

<miguel> I have a vague recollection that we talked about it, and that I thought
         'not a bug' ...
<miguel> ... finally meaning 'before this command returns', and your ops making
         sure that the command in question never returned ...
<miguel> ... so that 'never' satisfies 'before the command returns'