forked from MirrorHub/synapse
Fix potential race in _start_key_lookups
If the verify_request.deferred has already completed, then `remove_deferreds` will be called immediately. It therefore might resolve the server_to_deferred deferred while there are still other requests for that server in flight. To avoid that, we should build the complete list of requests, and *then* add the callbacks.
This commit is contained in:
parent
afbd773dc6
commit
abdefb8a01
1 changed files with 8 additions and 5 deletions
|
@ -172,7 +172,13 @@ class Keyring(object):
|
||||||
# map from server name to a set of request ids
|
# map from server name to a set of request ids
|
||||||
server_to_request_ids = {}
|
server_to_request_ids = {}
|
||||||
|
|
||||||
def remove_deferreds(res, server_name, verify_request):
|
for verify_request in verify_requests:
|
||||||
|
server_name = verify_request.server_name
|
||||||
|
request_id = id(verify_request)
|
||||||
|
server_to_request_ids.setdefault(server_name, set()).add(request_id)
|
||||||
|
|
||||||
|
def remove_deferreds(res, verify_request):
|
||||||
|
server_name = verify_request.server_name
|
||||||
request_id = id(verify_request)
|
request_id = id(verify_request)
|
||||||
server_to_request_ids[server_name].discard(request_id)
|
server_to_request_ids[server_name].discard(request_id)
|
||||||
if not server_to_request_ids[server_name]:
|
if not server_to_request_ids[server_name]:
|
||||||
|
@ -182,11 +188,8 @@ class Keyring(object):
|
||||||
return res
|
return res
|
||||||
|
|
||||||
for verify_request in verify_requests:
|
for verify_request in verify_requests:
|
||||||
server_name = verify_request.server_name
|
|
||||||
request_id = id(verify_request)
|
|
||||||
server_to_request_ids.setdefault(server_name, set()).add(request_id)
|
|
||||||
verify_request.deferred.addBoth(
|
verify_request.deferred.addBoth(
|
||||||
remove_deferreds, server_name, verify_request,
|
remove_deferreds, verify_request,
|
||||||
)
|
)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
Loading…
Reference in a new issue