diff options
author | Erik Johnston <erik@matrix.org> | 2018-11-28 20:09:39 +0000 |
---|---|---|
committer | Brendan Abolivier <babolivier@matrix.org> | 2019-02-13 15:16:04 +0000 |
commit | b951f35572119749eee0160b70b5b76382223103 (patch) | |
tree | 2b96a38f61727a06d5075b34bd7428a45d7a437d | |
parent | Update maps and proxy (diff) | |
download | synapse-b951f35572119749eee0160b70b5b76382223103.tar.xz |
Reduce size of fed transaction IDs
-rw-r--r-- | synapse/federation/transaction_queue.py | 21 | ||||
-rw-r--r-- | synapse/http/endpoint.py | 7 |
2 files changed, 24 insertions, 4 deletions
diff --git a/synapse/federation/transaction_queue.py b/synapse/federation/transaction_queue.py index ba3b3fd2f9..00bbf01620 100644 --- a/synapse/federation/transaction_queue.py +++ b/synapse/federation/transaction_queue.py @@ -17,6 +17,7 @@ import logging import random import json import opentracing +import string from six import itervalues @@ -135,7 +136,7 @@ class TransactionQueue(object): self.last_device_list_stream_id_by_dest = {} # HACK to get unique tx id - self._next_txn_id = int(self.clock.time_msec()) + self._next_txn_id = 1 self._order = 1 @@ -486,7 +487,7 @@ class TransactionQueue(object): pending_pdus = [] while True: - txn_id = str(self._next_txn_id) + txn_id = _encode_id(self._next_txn_id) self._next_txn_id += 1 for s in pdu_spans.values(): @@ -860,3 +861,19 @@ class TransactionQueue(object): new_destinations = set(pdu.unsigned.get("destinations", [])) new_destinations.discard(destination) yield self._send_pdu(pdu, list(new_destinations), span) + + +def _numberToBase(n, b): + if n == 0: + return [0] + digits = [] + while n: + digits.append(int(n % b)) + n //= b + return digits[::-1] + + +def _encode_id(i): + digits = string.digits + string.ascii_letters + val_slice = _numberToBase(i, len(digits)) + return "".join(digits[x] for x in val_slice) diff --git a/synapse/http/endpoint.py b/synapse/http/endpoint.py index 91025037a3..df528113a4 100644 --- a/synapse/http/endpoint.py +++ b/synapse/http/endpoint.py @@ -194,8 +194,11 @@ class _WrappedConnection(object): # In Twisted >18.4; the TLS connection will be None if it has closed # which will make abortConnection() throw. Check that the TLS connection # is not None before trying to close it. - if self.transport.getHandle() is not None: - self.transport.abortConnection() + try: + if self.transport.getHandle() is not None: + self.transport.abortConnection() + except: + logger.warning("Failed to abort connection") def request(self, request): self.last_request = time.time() |