diff options
author | Mike Taylor <bear42@gmail.com> | 2015-07-31 11:21:01 -0400 |
---|---|---|
committer | Mike Taylor <bear42@gmail.com> | 2015-07-31 11:21:01 -0400 |
commit | 2c69144189cc267de1fd293f3a2da7f79f86e572 (patch) | |
tree | ce27b09840793b4152e67e1dc3113f04289d5d1b /sleekxmpp/jid.py | |
parent | bb094cc6498838cece046d9ed74881232fb5010d (diff) | |
parent | f54ebec654fa14ed1db85d141c5268e60ac6d737 (diff) | |
download | slixmpp-2c69144189cc267de1fd293f3a2da7f79f86e572.tar.gz slixmpp-2c69144189cc267de1fd293f3a2da7f79f86e572.tar.bz2 slixmpp-2c69144189cc267de1fd293f3a2da7f79f86e572.tar.xz slixmpp-2c69144189cc267de1fd293f3a2da7f79f86e572.zip |
Merge pull request #387 from mcella/378
Fixes #378: must acquire JID_CACHE_LOCK before adding to JID_CACHE
Diffstat (limited to 'sleekxmpp/jid.py')
-rw-r--r-- | sleekxmpp/jid.py | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/sleekxmpp/jid.py b/sleekxmpp/jid.py index 613b272e..754a3d3a 100644 --- a/sleekxmpp/jid.py +++ b/sleekxmpp/jid.py @@ -72,19 +72,18 @@ JID_CACHE_LOCK = threading.Lock() JID_CACHE_MAX_SIZE = 1024 def _cache(key, parts, locked): - JID_CACHE[key] = (parts, locked) - if len(JID_CACHE) > JID_CACHE_MAX_SIZE: - with JID_CACHE_LOCK: - while len(JID_CACHE) > JID_CACHE_MAX_SIZE: - found = None - for key, item in JID_CACHE.items(): - if not item[1]: # if not locked - found = key - break - if not found: # more than MAX_SIZE locked - # warn? + with JID_CACHE_LOCK: + JID_CACHE[key] = (parts, locked) + while len(JID_CACHE) > JID_CACHE_MAX_SIZE: + found = None + for key, item in JID_CACHE.items(): + if not item[1]: # if not locked + found = key break - del JID_CACHE[found] + if not found: # more than MAX_SIZE locked + # warn? + break + del JID_CACHE[found] # pylint: disable=c0103 #: The nodeprep profile of stringprep used to validate the local, |