mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-07-27 02:35:19 -04:00
Clean up startup for the pusher (#6558)
* Remove redundant python2 support code `str.decode()` doesn't exist on python3, so presumably this code was doing nothing * Filter out pushers with corrupt data When we get a row with unparsable json, drop the row, rather than returning a row with null `data`, which will then cause an explosion later on. * Improve logging when we can't start a pusher Log the ID to help us understand the problem * Make email pusher setup more robust We know we'll have a `data` member, since that comes from the database. What we *don't* know is if that is a dict, and if that has a `brand` member, and if that member is a string.
This commit is contained in:
parent
7963ca83cb
commit
d6752ce5da
7 changed files with 44 additions and 42 deletions
|
@ -15,8 +15,7 @@
|
|||
# limitations under the License.
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
from typing import Iterable, Iterator
|
||||
|
||||
from canonicaljson import encode_canonical_json, json
|
||||
|
||||
|
@ -27,21 +26,16 @@ from synapse.util.caches.descriptors import cachedInlineCallbacks, cachedList
|
|||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if six.PY2:
|
||||
db_binary_type = six.moves.builtins.buffer
|
||||
else:
|
||||
db_binary_type = memoryview
|
||||
|
||||
|
||||
class PusherWorkerStore(SQLBaseStore):
|
||||
def _decode_pushers_rows(self, rows):
|
||||
def _decode_pushers_rows(self, rows: Iterable[dict]) -> Iterator[dict]:
|
||||
"""JSON-decode the data in the rows returned from the `pushers` table
|
||||
|
||||
Drops any rows whose data cannot be decoded
|
||||
"""
|
||||
for r in rows:
|
||||
dataJson = r["data"]
|
||||
r["data"] = None
|
||||
try:
|
||||
if isinstance(dataJson, db_binary_type):
|
||||
dataJson = str(dataJson).decode("UTF8")
|
||||
|
||||
r["data"] = json.loads(dataJson)
|
||||
except Exception as e:
|
||||
logger.warning(
|
||||
|
@ -50,12 +44,9 @@ class PusherWorkerStore(SQLBaseStore):
|
|||
dataJson,
|
||||
e.args[0],
|
||||
)
|
||||
pass
|
||||
continue
|
||||
|
||||
if isinstance(r["pushkey"], db_binary_type):
|
||||
r["pushkey"] = str(r["pushkey"]).decode("UTF8")
|
||||
|
||||
return rows
|
||||
yield r
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def user_has_pusher(self, user_id):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue