[racket] Custodian behavior on normal exit

From: Tobias Hammer (tobias.hammer at dlr.de)
Date: Wed Oct 30 10:16:46 EDT 2013

Custodians can have entries that are cleaned up on program exit and  
entries that are only cleaned up whenever a custodian is (regularly) shut  

See http://docs.racket-lang.org/inside/Custodians.html
scheme_add_managed vs. scheme_add_managed_close_on_exit	

As far as i can tell the subprocess is added with scheme_add_managed.  
Patching this to *_close_on_exit changes the behavior to what the OP  
expect. I'm not sure if close on exit or not is the better default for  
subprocesses, better ask Matthew what his intentions were.


The patch:

diff --git a/racket/src/racket/src/port.c b/racket/src/racket/src/port.c
index f2a1811..cc99888 100644
--- a/racket/src/racket/src/port.c
+++ b/racket/src/racket/src/port.c
@@ -10090,7 +10090,7 @@ static Scheme_Object *subprocess(int c,  
Scheme_Object *args[])
        closer = interrupt_subproc;

-    mref = scheme_add_managed(NULL, (Scheme_Object *)subproc, closer,  
NULL, 1);
+    mref = scheme_add_managed_close_on_exit(NULL, (Scheme_Object  
*)subproc, closer, NULL);
      subproc->mref = mref;

On Wed, 30 Oct 2013 14:48:25 +0100, Asumu Takikawa <asumu at ccs.neu.edu>  

> On 2013-10-28 18:39:23 -0400, Jonathan Schuster wrote:
>>    My assumption was that the root custodian would always call
>>    custodian-shutdown-all on itself when a Racket process ends,  
>> regardless of
>>    whether the process is shutting down gracefully or not. Is that not  
>> the
>>    case?
> I suspect the issue here is the caveat described in the docs for
> `current-subprocess-custodian-mode`:
>   Custodian-triggered shutdown is limited by details of process handling
>   in the host system. For example, process and system may create an
>   intermediate shell process to run a program, in which case
>   custodian-based termination shuts down the shell process and probably
>   not the process started by the shell. See also subprocess-kill. Process
>   groups (see subprocess-group-enabled) can address some limitations, but
>   not all of them.
> My guess is that running "racket" from a subprocess spawns additional
> processes that aren't controlled from the custodian. I noticed that if
> you change the program from "racket" to running "bin/cat", for example,
> the subprocess does seem to be terminated.
> (I don't actually know much about custodians so this could be all wrong)
> Cheers,
> Asumu
> ____________________
>   Racket Users list:
>   http://lists.racket-lang.org/users

Tobias Hammer
DLR / Robotics and Mechatronics Center (RMC)
Muenchner Str. 20, D-82234 Wessling
Tel.: 08153/28-1487
Mail: tobias.hammer at dlr.de

Posted on the users mailing list.