diff options
author | drebs <drebs@riseup.net> | 2017-10-11 11:06:34 -0300 |
---|---|---|
committer | drebs <drebs@riseup.net> | 2017-10-11 11:11:14 -0300 |
commit | 1cde86239f68ca8fa896ecf4ffc6b891eeb837e3 (patch) | |
tree | c7a054f96cb784f2dec3df5d33a54a8d35f356c1 | |
parent | f39a7f84b0f053a4e2483ee5d5ee5367683c40ee (diff) |
[bug] limit concurrent blob writes in server
If there's no limit to the number of concurrent blob writes in the
server, the maximum limit of open files will eventually be reached, and
the processing of requests will start crashing. This commit adds
a semaphore to limit the number of concurrent writes in the server.
Related: #8973
-rw-r--r-- | src/leap/soledad/server/_blobs.py | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/leap/soledad/server/_blobs.py b/src/leap/soledad/server/_blobs.py index e0763028..cd47098d 100644 --- a/src/leap/soledad/server/_blobs.py +++ b/src/leap/soledad/server/_blobs.py @@ -64,6 +64,7 @@ class FilesystemBlobsBackend(object): def __init__(self, blobs_path='/tmp/blobs/', quota=200 * 1024): self.quota = quota + self.semaphore = defer.DeferredSemaphore(50) # TODO: make configurable if not os.path.isdir(blobs_path): os.makedirs(blobs_path) self.path = blobs_path @@ -103,6 +104,7 @@ class FilesystemBlobsBackend(object): @defer.inlineCallbacks def write_blob(self, user, blob_id, request, namespace=''): + yield self.semaphore.acquire() path = self._get_path(user, blob_id, namespace) try: mkdir_p(os.path.split(path)[0]) @@ -123,6 +125,7 @@ class FilesystemBlobsBackend(object): fbp = FileBodyProducer(request.content) with open(path, 'wb') as blobfile: yield fbp.startProducing(blobfile) + yield self.semaphore.release() def delete_blob(self, user, blob_id, request, namespace=''): blob_path = self._get_path(user, blob_id, namespace) |