Skip to content

Commit

Permalink
Merge pull request #166 from amirmiron/sendlock_deadlock
Browse files Browse the repository at this point in the history
deadlock on _sendlock caused by GC on netref
  • Loading branch information
tomerfiliba committed Apr 15, 2015
2 parents 14d88ad + 8c1eff8 commit 1403794
Showing 1 changed file with 9 additions and 0 deletions.
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

0 comments on commit 1403794

Please sign in to comment.