Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Replace ujson with simplejson #3008

Merged
merged 4 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Changes in synapse v0.26.1 (2018-03-15)
=======================================

Bug fixes:

* Fix bug where an invalid event caused server to stop functioning correctly,
due to parsing and serializing bugs in ujson library.

Changes in synapse v0.26.0 (2018-01-05)
=======================================

Expand Down
2 changes: 1 addition & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
""" This is a reference implementation of a Matrix home server.
"""

__version__ = "0.26.0"
__version__ = "0.26.1"
2 changes: 1 addition & 1 deletion synapse/api/filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from synapse.types import UserID, RoomID
from twisted.internet import defer

import ujson as json
import simplejson as json
import jsonschema
from jsonschema import FormatChecker

Expand Down
2 changes: 1 addition & 1 deletion synapse/handlers/e2e_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import ujson as json
import simplejson as json
import logging

from canonicaljson import encode_canonical_json
Expand Down
6 changes: 3 additions & 3 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

import logging
import random
import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -561,8 +561,8 @@ def handle_new_client_event(

# Ensure that we can round trip before trying to persist in db
try:
dump = ujson.dumps(unfreeze(event.content))
ujson.loads(dump)
dump = simplejson.dumps(unfreeze(event.content))
simplejson.loads(dump)
except Exception:
logger.exception("Failed to encode content: %r", event.content)
raise
Expand Down
5 changes: 2 additions & 3 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import collections
import logging
import urllib
import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -370,8 +370,7 @@ def respond_with_json(request, code, json_object, send_cors=False,
if canonical_json or synapse.events.USE_FROZEN_DICTS:
json_bytes = encode_canonical_json(json_object)
else:
# ujson doesn't like frozen_dicts.
json_bytes = ujson.dumps(json_object, ensure_ascii=False)
json_bytes = simplejson.dumps(json_object)

return respond_with_json_bytes(
request, code, json_bytes,
Expand Down
2 changes: 1 addition & 1 deletion synapse/replication/tcp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"""

import logging
import ujson as json
import simplejson as json


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v1/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

import logging
import urllib
import ujson as json
import simplejson as json

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/client/v2_alpha/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import itertools
import logging

import ujson as json
import simplejson as json

logger = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion synapse/rest/media/v1/preview_url_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import re
import fnmatch
import cgi
import ujson as json
import simplejson as json
import urlparse
import itertools
import datetime
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from synapse.util.caches.descriptors import cached, cachedList, cachedInlineCallbacks

import ujson as json
import simplejson as json
import logging

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/background_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from twisted.internet import defer

import ujson as json
import simplejson as json
import logging

logger = logging.getLogger(__name__)
Expand Down
12 changes: 6 additions & 6 deletions synapse/storage/deviceinbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# limitations under the License.

import logging
import ujson
import simplejson

from twisted.internet import defer

Expand Down Expand Up @@ -85,7 +85,7 @@ def add_messages_txn(txn, now_ms, stream_id):
)
rows = []
for destination, edu in remote_messages_by_destination.items():
edu_json = ujson.dumps(edu)
edu_json = simplejson.dumps(edu)
rows.append((destination, stream_id, now_ms, edu_json))
txn.executemany(sql, rows)

Expand Down Expand Up @@ -177,7 +177,7 @@ def _add_messages_to_local_device_inbox_txn(self, txn, stream_id,
" WHERE user_id = ?"
)
txn.execute(sql, (user_id,))
message_json = ujson.dumps(messages_by_device["*"])
message_json = simplejson.dumps(messages_by_device["*"])
for row in txn:
# Add the message for all devices for this user on this
# server.
Expand All @@ -199,7 +199,7 @@ def _add_messages_to_local_device_inbox_txn(self, txn, stream_id,
# Only insert into the local inbox if the device exists on
# this server
device = row[0]
message_json = ujson.dumps(messages_by_device[device])
message_json = simplejson.dumps(messages_by_device[device])
messages_json_for_user[device] = message_json

if messages_json_for_user:
Expand Down Expand Up @@ -253,7 +253,7 @@ def get_new_messages_for_device_txn(txn):
messages = []
for row in txn:
stream_pos = row[0]
messages.append(ujson.loads(row[1]))
messages.append(simplejson.loads(row[1]))
if len(messages) < limit:
stream_pos = current_stream_id
return (messages, stream_pos)
Expand Down Expand Up @@ -389,7 +389,7 @@ def get_new_messages_for_remote_destination_txn(txn):
messages = []
for row in txn:
stream_pos = row[0]
messages.append(ujson.loads(row[1]))
messages.append(simplejson.loads(row[1]))
if len(messages) < limit:
stream_pos = current_stream_id
return (messages, stream_pos)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/devices.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import ujson as json
import simplejson as json

from twisted.internet import defer

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/end_to_end_keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from synapse.util.caches.descriptors import cached

from canonicaljson import encode_canonical_json
import ujson as json
import simplejson as json

from ._base import SQLBaseStore

Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/event_push_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .stream import lower_bound

import logging
import ujson as json
import simplejson as json

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import synapse.metrics

import logging
import ujson as json
import simplejson as json

# these are only included to make the type annotations work
from synapse.events import EventBase # noqa: F401
Expand All @@ -56,7 +56,7 @@

def encode_json(json_object):
if USE_FROZEN_DICTS:
# ujson doesn't like frozen_dicts
# simplejson doesn't like frozen_dicts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh, I thought i'd explicitly not changed that :/

return encode_canonical_json(json_object)
else:
return json.dumps(json_object, ensure_ascii=False)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/receipts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from twisted.internet import defer

import logging
import ujson as json
import simplejson as json


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import collections
import logging
import ujson as json
import simplejson as json
import re

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/roommember.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from synapse.types import get_domain_from_id

import logging
import ujson as json
import simplejson as json

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/schema/delta/25/fts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from synapse.storage.prepare_database import get_statements
from synapse.storage.engines import PostgresEngine, Sqlite3Engine

import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,7 +66,7 @@ def run_create(cur, database_engine, *args, **kwargs):
"max_stream_id_exclusive": max_stream_id + 1,
"rows_inserted": 0,
}
progress_json = ujson.dumps(progress)
progress_json = simplejson.dumps(progress)

sql = (
"INSERT into background_updates (update_name, progress_json)"
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/schema/delta/27/ts.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from synapse.storage.prepare_database import get_statements

import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/schema/delta/31/search_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from synapse.storage.prepare_database import get_statements

import logging
import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -49,7 +49,7 @@ def run_create(cur, database_engine, *args, **kwargs):
"rows_inserted": 0,
"have_added_indexes": False,
}
progress_json = ujson.dumps(progress)
progress_json = simplejson.dumps(progress)

sql = (
"INSERT into background_updates (update_name, progress_json)"
Expand Down
4 changes: 2 additions & 2 deletions synapse/storage/schema/delta/33/event_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from synapse.storage.prepare_database import get_statements

import logging
import ujson
import simplejson

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,7 +44,7 @@ def run_create(cur, database_engine, *args, **kwargs):
"max_stream_id_exclusive": max_stream_id + 1,
"rows_inserted": 0,
}
progress_json = ujson.dumps(progress)
progress_json = simplejson.dumps(progress)

sql = (
"INSERT into background_updates (update_name, progress_json)"
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import logging
import re
import ujson as json
import simplejson as json


logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from synapse.util.caches.descriptors import cached
from twisted.internet import defer

import ujson as json
import simplejson as json
import logging

logger = logging.getLogger(__name__)
Expand Down
2 changes: 1 addition & 1 deletion synapse/storage/transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from collections import namedtuple

import logging
import ujson as json
import simplejson as json

logger = logging.getLogger(__name__)

Expand Down