Skip to content

Commit

Permalink
Keep a hard reference to connection in netrefs
Browse files Browse the repository at this point in the history
This means that netrefs will now keep connections alive.

This may be related to several EOFError issues where the program only
keeps reference to a netref, but not the connection.

May also be related to pypy related EOFError issues where weakref.proxy
may have problems, see #237.
  • Loading branch information
coldfix committed Mar 7, 2018
1 parent 00da334 commit e1570e5
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
8 changes: 2 additions & 6 deletions rpyc/core/netref.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ def syncreq(proxy, handler, *args):
:raises: any exception raised by the operation will be raised
:returns: the result of the operation
"""
conn = object.__getattribute__(proxy, "____conn__")()
if not conn:
raise ReferenceError('weakly-referenced object no longer exists')
conn = object.__getattribute__(proxy, "____conn__")
return conn.sync_request(handler, proxy, *args)

def asyncreq(proxy, handler, *args):
Expand All @@ -88,9 +86,7 @@ def asyncreq(proxy, handler, *args):
:returns: an :class:`~rpyc.core.async_.AsyncResult` representing
the operation
"""
conn = object.__getattribute__(proxy, "____conn__")()
if not conn:
raise ReferenceError('weakly-referenced object no longer exists')
conn = object.__getattribute__(proxy, "____conn__")
return conn.async_request(handler, proxy, *args)

class NetrefMetaclass(type):
Expand Down
7 changes: 3 additions & 4 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
The RPyC protocol
"""
import sys
import weakref
import itertools
import socket
import time
Expand Down Expand Up @@ -283,7 +282,7 @@ def _box(self, obj):
return consts.LABEL_VALUE, obj
if type(obj) is tuple:
return consts.LABEL_TUPLE, tuple(self._box(item) for item in obj)
elif isinstance(obj, netref.BaseNetref) and obj.____conn__() is self:
elif isinstance(obj, netref.BaseNetref) and obj.____conn__ is self:
return consts.LABEL_LOCAL_REF, obj.____oid__
else:
self._local_objects.add(obj)
Expand Down Expand Up @@ -330,7 +329,7 @@ def _netref_factory(self, oid, clsname, modname):
info = self.sync_request(consts.HANDLE_INSPECT, oid)
cls = netref.class_factory(clsname, modname, info)
self._netref_classes_cache[typeinfo] = cls
return cls(weakref.ref(self), oid)
return cls(self, oid)

#
# dispatching
Expand Down Expand Up @@ -536,7 +535,7 @@ def async_request(self, handler, *args, **kwargs):
timeout = kwargs.pop("timeout", None)
if kwargs:
raise TypeError("got unexpected keyword argument(s) %s" % (list(kwargs.keys()),))
res = AsyncResult(weakref.proxy(self))
res = AsyncResult(self)
self._async_request(handler, args, res)
if timeout is not None:
res.set_expiry(timeout)
Expand Down

0 comments on commit e1570e5

Please sign in to comment.