Skip to content

Enhancement request: anonymous connections

4 messages · Duncan Murdoch, Brian Ripley, Seth Falcon

#
On 12/28/2005 9:50 AM, Seth Falcon wrote:
No it doesn't.  However, I've committed the small fix.
I think the general problem is that R doesn't have references (or at 
least, they aren't in a final, documented state).  If the garbage 
collector closed a connection, then things would go wrong when there 
were two copies of it:  the second one would be messed up when the first 
was destroyed.  If we had references, then opening a connection could 
create a connection object and a reference to it; the connection object 
would remain as long as there were any references to it, and could be 
destroyed (and automatically closed) after the last reference was gone.

Duncan Murdoch
#
On Sun, 1 Jan 2006, Duncan Murdoch wrote:

            
It was not even a bug in load: close() and open() are not pairs.  (I 
didn't pick the names!) Your `fix' destroys a connection, which is 
not the documented behaviour and far more dangerous than leaving it open.

The lifecycle of a connection is  (see e.g. my R-news article)

 	create->open->close->destroy

and close() does both of the last two.  Please revert this change. 
Ideally we would close and not destroy if the connection was opened, but 
that needs a better C-level interface in place of this R-level one.
However, that just isn't how connections are documented in the Green Book 
(referenced on all the relevant help pages, so required reading) and 
getConnection() allows you to create an R object pointing to a connection 
that previously had none.  The OP has never told us what `anonymous 
connections' are, but it is quite possible that his unstated ideas are 
incompatible with the documentation.
#
On 1/1/2006 1:05 PM, Prof Brian Ripley wrote:
Sorry about that.  I've done the reversion.

Is it worth putting that C-level interface in place to make load() more 
compatible with ?connections which says,

      'open' opens a connection.  In general functions using connections
      will open them if they are not open, but then close them again, so
      to leave a connection open call 'open' explicitly.

?  I suppose a natural way to do it would be to add a "destroy=TRUE"
argument to close(), and then have load() do

  on.exit(close(con, destroy=FALSE))

but maybe it would be better to add a separate function to do this, for 
better green book compatibility.

Duncan Murdoch
2 days later
#
On 1 Jan 2006, ripley at stats.ox.ac.uk wrote:
Yes, p. 384 of my copy of the Green Book explains:

    Once a connection has been opened, the evaluation manager keeps it
    open until it is explicitly closed, or the session ends, even if
    no corresponding S connection object exists.

What are some advantages of this design choice?
Yep.  The current behavior is as documented in the Green Book and yes,
the enhancement I would like is incompatible with that documentation.

What is an anonymous connection?  Well, really what I want is for the
evaluation manager to clean up connections that have no corresponding
S connection objects referring to them.  Then the code examples that
are part of this thread would work.


+ seth