Skip to content

json.decoder.JSONDecodeError on sync (mangled event JSON) #19128

Description

@emdete

Description

When trying to login from a web client I see this snipped in the log on the server and the client hangs forever:

Android clients work well. Older Synapse worked as well with this setup. the server in question was setup several years ago already. it seems to be related to an update to synapse. i am running matrix-synapse 1.139.2-1 on a Devuan system.

Steps to reproduce

  • Start a web-element somewhere
  • Point homeserver to my server
  • Try to log in

Homeserver

my homeserver

Synapse Version

1.139.2

Installation Method

Other (please mention below)

Database

pg 13, single database, ported from sqlite, never restored from backup.

Workers

Single process

Platform

Devuan Ceres (unstable)

6.3.0-2-amd64, Debian 6.3.11-1

bare metal

Configuration

none of those

Relevant log output

2025-11-02 18:32:53,722 - synapse.http.server - 151 - ERROR - GET-7049- Failed handle request via 'SyncRestServlet': <XForwardedForRequest at 0x7f1b09112d50 method='GET' uri='/_matrix/client/v3/sync?filter=8&timeout=0&org.matrix.msc4222.use_state_after=true&_cacheBuster=1762108373545' clientproto='HTTP/1.1' site='800
8'>
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/synapse/http/server.py", line 339, in _async_render_wrapper
    callback_return = await self._async_render(request)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/http/server.py", line 564, in _async_render
    callback_return = await raw_callback_return
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/rest/client/sync.py", line 268, in on_GET
    sync_result = await self.sync_handler.wait_for_sync_for_user(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<6 lines>...
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 364, in wait_for_sync_for_user
    res = await self.response_cache.wrap(
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/util/caches/response_cache.py", line 314, in wrap
    return await make_deferred_yieldable(result)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1195, in __iter__
    result.raiseException()
    ~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 455, in raiseException
    raise self.value.with_traceback(self.tb)
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1853, in _inlineCallbacks
    result = context.run(
        cast(Failure, result).throwExceptionIntoGenerator, gen
    )
  File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 467, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/util/caches/response_cache.py", line 292, in cb
    return await callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 465, in _wait_for_sync_for_user
    result = await self.current_sync_for_user(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        sync_config, since_token, full_state=full_state
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 533, in current_sync_for_user
    sync_result = await self.generate_sync_result(
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        sync_config, since_token, full_state
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 1724, in generate_sync_result
    ) = await self._generate_sync_entry_for_rooms(sync_result_builder)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 2238, in _generate_sync_entry_for_rooms
    await concurrently_execute(handle_room_entries, room_entries, 10)
  File "/usr/lib/python3/dist-packages/synapse/util/async_helpers.py", line 259, in concurrently_execute
    await yieldable_gather_results(
    ...<2 lines>...
    )
  File "/usr/lib/python3/dist-packages/synapse/util/async_helpers.py", line 308, in yieldable_gather_results
    raise dfe.subFailure.value from None
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1853, in _inlineCallbacks
    result = context.run(
        cast(Failure, result).throwExceptionIntoGenerator, gen
    )
  File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 467, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/util/async_helpers.py", line 245, in _concurrently_execute_inner
    await maybe_awaitable(func(value))
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 2227, in handle_room_entries
    await self._generate_room_entry(
    ...<6 lines>...
    )
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 2746, in _generate_room_entry
    state = await self.compute_state_delta(
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<7 lines>...
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/handlers/sync.py", line 1165, in compute_state_delta
    state = await self.store.get_events(list(state_ids.values()))
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 618, in get_events
    events = await self.get_events_as_list(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<4 lines>...
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 674, in get_events_as_list
    event_entry_map = await self.get_unredacted_events_from_cache_or_db(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        set(event_ids), allow_rejected=allow_rejected
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 911, in get_unredacted_events_from_cache_or_db
    missing_events: Dict[str, EventCacheEntry] = await delay_cancellation(
                                                 ^^^^^^^^^^^^^^^^^^^^^^^^^
        get_missing_events_from_cache_or_db()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1187, in __iter__
    yield self
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1853, in _inlineCallbacks
    result = context.run(
        cast(Failure, result).throwExceptionIntoGenerator, gen
    )
  File "/usr/lib/python3/dist-packages/twisted/python/failure.py", line 467, in throwExceptionIntoGenerator
    return g.throw(self.value.with_traceback(self.tb))
           ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 897, in get_missing_events_from_cache_or_db
    raise e
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 890, in get_missing_events_from_cache_or_db
    db_missing_events = await self._get_events_from_db(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        missing_events_ids - missing_events.keys(),
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 1368, in _get_events_from_db
    event_ids_to_fetch = await _fetch_event_ids_and_get_outstanding_redactions(
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        event_ids
        ^^^^^^^^^
    )
    ^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 1353, in _fetch_event_ids_and_get_outstanding_redactions
    row_map = await self._enqueue_events(event_ids_to_fetch)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 1538, in _enqueue_events
    row_map = await events_d
              ^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/twisted/internet/defer.py", line 1187, in __iter__
    yield self
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 1286, in _fetch_event_list
    row_dict = self.db_pool.new_transaction(
        conn,
    ...<5 lines>...
        events_to_fetch,
    )
  File "/usr/lib/python3/dist-packages/synapse/storage/database.py", line 821, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "/usr/lib/python3/dist-packages/synapse/storage/databases/main/events_worker.py", line 1618, in _fetch_event_rows
    event_json = json.loads(event.json)
  File "/usr/lib/python3.13/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ~~~~~~~~~~~~~~~~~~~~~~~^^^
  File "/usr/lib/python3.13/json/decoder.py", line 345, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/json/decoder.py", line 363, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Anything else that would be useful to know?

The whole thing started with element-web not being able to show pics (or media) while android element-x could do so. That's why I started to create a new session which didn't work at all. Existing sessions seem to work but suffer from not being able to show/download media.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions