Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream writer problem #17243

Closed
yixiangfeng opened this issue May 29, 2024 · 2 comments
Closed

stream writer problem #17243

yixiangfeng opened this issue May 29, 2024 · 2 comments

Comments

@yixiangfeng
Copy link

yixiangfeng commented May 29, 2024

Description

I try to add events to stream_writers. no setup other. when client call read receipt backend throw error

Steps to reproduce

when front end call read receipt api backend can‘t can write to receipts. event persist is work. so need to setup the typing worker or no need? i expect have a default solution

Homeserver

another homeserver

Synapse Version

1.107.0

Installation Method

Docker (matrixdotorg/synapse)

Database

postgresql

Workers

Multiple workers

Platform

container

Configuration

homeserver.config

listeners:
  - port: 9093
    type: http
    x_forwarded: true
    resources:
     - names: [replication]

instance_map:
 main:
   host: localhost
   port: 9093
   tls: false
 event_persister:
   host: localhost
   port: 9094
   tls: false
stream_writers: 
 events: event_persister

worker.config

worker_app: synapse.app.generic_worker
worker_name: event_persister

worker_listeners:
  - type: http
    port: 9094
    x_forwarded: true
    resources:
      - names: [replication]

Relevant log output

2024-05-29 15:39:40,077 - synapse.http.server - 146 - ERROR - POST-420 - Failed handle request via 'ReceiptRestServlet': <XForwardedForRequest at 0x7fe51050f550 method='POST' uri='/_matrix/client/v3/rooms/!KsIbRqzbBMwXKMigpY%3Astaging2.closer.contact/receipt/m.read/%24qP0tlwcYfC-txrW4OM0QYOxcjsIh8NgIRiugX5Er2Qw' client_ip='172.31.2.136' clientproto='HTTP/1.1' site='8008'>

 Traceback (most recent call last):

   File "/usr/local/lib/python3.11/site-packages/synapse/http/server.py", line 332, in _async_render_wrapper

     callback_return = await self._async_render(request)

                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   File "/usr/local/lib/python3.11/site-packages/synapse/http/server.py", line 544, in _async_render

     callback_return = await raw_callback_return

                       ^^^^^^^^^^^^^^^^^^^^^^^^^

   File "/usr/local/lib/python3.11/site-packages/synapse/rest/client/receipts.py", line 115, in on_POST

     await self.receipts_handler.received_client_receipt(

   File "/usr/local/lib/python3.11/site-packages/synapse/handlers/receipts.py", line 203, in received_client_receipt

     is_new = await self._handle_new_receipts([receipt])

              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   File "/usr/local/lib/python3.11/site-packages/synapse/handlers/receipts.py", line 144, in _handle_new_receipts

     stream_id = await self.store.insert_receipt(

                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

   File "/usr/local/lib/python3.11/site-packages/synapse/storage/databases/main/receipts.py", line 856, in insert_receipt

     assert self._can_write_to_receipts

            ^^^^^^^^^^^^^^^^^^^^^^^^^^^

 AssertionError


### Anything else that would be useful to know?

_No response_
@evoL
Copy link
Contributor

evoL commented Nov 22, 2024

I'm hitting the same issue as of a few days ago:

Failed handle request via 'ReceiptRestServlet': <SynapseRequest at 0x7f2ca3be0550 method='POST' uri='/_matrix/client/v3/rooms/!zIsbXIPtKQoNyaZZfX%3Ahackerspace.pl/receipt/m.read/%24J0GWhWS32JGHatNKhsA4Gnmv7njc6KEvqWEpSTTbJjo' clientproto='HTTP/1.1' site='8083'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/synapse/http/server.py", line 332, in _async_render_wrapper
    callback_return = await self._async_render(request)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/synapse/http/server.py", line 544, in _async_render
    callback_return = await raw_callback_return
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/synapse/rest/client/receipts.py", line 115, in on_POST
    await self.receipts_handler.received_client_receipt(
  File "/usr/local/lib/python3.11/site-packages/synapse/handlers/receipts.py", line 203, in received_client_receipt
    is_new = await self._handle_new_receipts([receipt])
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/synapse/handlers/receipts.py", line 144, in _handle_new_receipts
    stream_id = await self.store.insert_receipt(
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/synapse/storage/databases/main/receipts.py", line 1060, in insert_receipt
    assert self._can_write_to_receipts
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError

How did you solve the issue in the end?

@evoL
Copy link
Contributor

evoL commented Nov 22, 2024

I figured it out myself in the end. The problem was that my worker was not configured as a stream writer, hence self._can_write_to_receipts was false.

I ended up in this situation because I recently updated my reverse proxy configuration to match the latest version of regular expressions listed in the synapse.app.generic_worker documentation.

The list includes regexps for account data, receipts and presence requests:

# Account data requests
^/_matrix/client/(r0|v3|unstable)/.*/tags
^/_matrix/client/(r0|v3|unstable)/.*/account_data

# Receipts requests
^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt
^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers

# Presence requests
^/_matrix/client/(api/v1|r0|v3|unstable)/presence/

However, later on in the documentation, the same paths are listed as ones that are supposed to be routed to a worker if it's configured as a stream writer.

I solved the issue by removing the regexps for account data, receipts and presence that I mentioned above from my reverse proxy configuration. I imagine that configuring the worker as a stream writer would also fix it.

MadLittleMods pushed a commit that referenced this issue Dec 9, 2024
…eric_worker docs (#17954)

POST requests for account data, receipts and presence require the worker
to be configured as a stream writer. The regular expressions in the
default list don't assume any HTTP method, so if the worker is not a
stream writer, the request fails.

The stream writer section of the documentation lists the same regexps as
the one I'm removing, so people configuring stream writers can still
configure their routing properly.

More context:
#17243 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants