summary refs log tree commit diff
path: root/synapse/rest/client/v1/base.py
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2016-11-10 14:49:26 +0000
committerKegan Dougal <kegan@matrix.org>2016-11-10 14:49:26 +0000
commit2771447c29402e1f26bb45bdb730bdd0fe02682f (patch)
tree76efee1716361d704b6c00d8e359cd30deaac830 /synapse/rest/client/v1/base.py
parentMerge pull request #1619 from matrix-org/erikj/pwd_provider_error (diff)
downloadsynapse-2771447c29402e1f26bb45bdb730bdd0fe02682f.tar.xz
Store Promise<Response> instead of Response for HTTP API transactions
This fixes a race whereby:
 - User hits an endpoint.
 - No cached transaction so executes main code.
 - User hits same endpoint.
 - No cache transaction so executes main code.
 - Main code finishes executing and caches response and returns.
 - Main code finishes executing and caches response and returns.

 This race is common in the wild when Synapse is struggling under load.
 This commit fixes the race by:
  - User hits an endpoint.
  - Caches the promise to execute the main code and executes main code.
  - User hits same endpoint.
  - Yields on the same promise as the first request.
  - Main code finishes executing and returns, unblocking both requests.
Diffstat (limited to 'synapse/rest/client/v1/base.py')
-rw-r--r--synapse/rest/client/v1/base.py4
1 files changed, 2 insertions, 2 deletions
diff --git a/synapse/rest/client/v1/base.py b/synapse/rest/client/v1/base.py
index c2a8447860..22c740c30c 100644
--- a/synapse/rest/client/v1/base.py
+++ b/synapse/rest/client/v1/base.py
@@ -18,7 +18,7 @@
 
 from synapse.http.servlet import RestServlet
 from synapse.api.urls import CLIENT_PREFIX
-from .transactions import HttpTransactionStore
+from .transactions import HttpTransactionCache
 import re
 
 import logging
@@ -59,4 +59,4 @@ class ClientV1RestServlet(RestServlet):
         self.hs = hs
         self.builder_factory = hs.get_event_builder_factory()
         self.auth = hs.get_v1auth()
-        self.txns = HttpTransactionStore()
+        self.txns = HttpTransactionCache()