Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deadlock on _sendlock caused by GC on netref #166

Merged
merged 1 commit into from
Apr 15, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions rpyc/core/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import itertools
import socket
import time
import gc

from threading import Lock, RLock, Event
from rpyc.lib.compat import pickle, next, is_py3k, maxint, select_error
Expand Down Expand Up @@ -235,11 +236,19 @@ def _get_seq_id(self):

def _send(self, msg, seq, args):
data = brine.dump((msg, seq, args))
# GC might run while sending data
# if so, a BaseNetref.__del__ might be called
# BaseNetref.__del__ must call asyncreq,
# which will cause a deadlock
is_gc_enabled = gc.isenabled()
gc.disable()
self._sendlock.acquire()
try:
self._channel.send(data)
finally:
self._sendlock.release()
if is_gc_enabled:
gc.enable()

def _send_request(self, seq, handler, args):
self._send(consts.MSG_REQUEST, seq, (handler, self._box(args)))
Expand Down