Skip to content

Commit e997039

Browse files
committed
remove read locks since list access is atomic
1 parent cac6b2f commit e997039

File tree

1 file changed

+9
-24
lines changed

1 file changed

+9
-24
lines changed

Diff for: src/cryptojwt/key_bundle.py

+9-24
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
import json
55
import logging
66
import os
7+
import threading
78
import time
89
from datetime import datetime
910
from functools import cmp_to_key
1011
from typing import List
1112
from typing import Optional
1213

1314
import requests
14-
from readerwriterlock import rwlock
1515

1616
from cryptojwt.jwk.ec import NIST2SEC
1717
from cryptojwt.jwk.hmac import new_sym_key
@@ -153,14 +153,6 @@ def ec_init(spec):
153153
return _kb
154154

155155

156-
def keys_reader(func):
157-
def wrapper(self, *args, **kwargs):
158-
with self._lock_reader:
159-
return func(self, *args, **kwargs)
160-
161-
return wrapper
162-
163-
164156
def keys_writer(func):
165157
def wrapper(self, *args, **kwargs):
166158
with self._lock_writer:
@@ -246,9 +238,7 @@ def __init__(
246238
self.source = None
247239
self.time_out = 0
248240

249-
self._lock = rwlock.RWLockFairD()
250-
self._lock_reader = self._lock.gen_rlock()
251-
self._lock_writer = self._lock.gen_wlock()
241+
self._lock_writer = threading.Lock()
252242

253243
if httpc:
254244
self.httpc = httpc
@@ -592,12 +582,11 @@ def get(self, typ="", only_active=True):
592582
"""
593583
self._uptodate()
594584

595-
with self._lock_reader:
596-
if typ:
597-
_typs = [typ.lower(), typ.upper()]
598-
_keys = [k for k in self._keys if k.kty in _typs]
599-
else:
600-
_keys = self._keys[:]
585+
if typ:
586+
_typs = [typ.lower(), typ.upper()]
587+
_keys = [k for k in self._keys[:] if k.kty in _typs]
588+
else:
589+
_keys = self._keys[:]
601590

602591
if only_active:
603592
return [k for k in _keys if not k.inactive_since]
@@ -612,8 +601,7 @@ def keys(self, update: bool = True):
612601
"""
613602
if update:
614603
self._uptodate()
615-
with self._lock_reader:
616-
return self._keys[:]
604+
return self._keys[:]
617605

618606
def active_keys(self):
619607
"""Return the set of active keys."""
@@ -685,7 +673,6 @@ def remove(self, key):
685673
except ValueError:
686674
pass
687675

688-
@keys_reader
689676
def __len__(self):
690677
"""
691678
The number of keys.
@@ -707,8 +694,7 @@ def get_key_with_kid(self, kid):
707694
:return: The key or None
708695
"""
709696
self._uptodate()
710-
with self._lock_reader:
711-
return self._get_key_with_kid(kid)
697+
return self._get_key_with_kid(kid)
712698

713699
def _get_key_with_kid(self, kid):
714700
for key in self._keys:
@@ -775,7 +761,6 @@ def remove_outdated(self, after, when=0):
775761
def __contains__(self, key):
776762
return key in self.keys()
777763

778-
@keys_reader
779764
def copy(self):
780765
"""
781766
Make deep copy of this KeyBundle

0 commit comments

Comments
 (0)