diff --git a/changelog.d/7927.misc b/changelog.d/7927.misc new file mode 100644 index 000000000..3b864da03 --- /dev/null +++ b/changelog.d/7927.misc @@ -0,0 +1 @@ +Optimisation to /sync handling: skip serializing the response if the client has already disconnected. diff --git a/synapse/rest/client/v2_alpha/sync.py b/synapse/rest/client/v2_alpha/sync.py index 9d8115072..a5c24fbd6 100644 --- a/synapse/rest/client/v2_alpha/sync.py +++ b/synapse/rest/client/v2_alpha/sync.py @@ -178,6 +178,12 @@ class SyncRestServlet(RestServlet): full_state=full_state, ) + # the client may have disconnected by now; don't bother to serialize the + # response if so. + if request._disconnected: + logger.info("Client has disconnected; not serializing response.") + return 200, {} + time_now = self.clock.time_msec() response_content = await self.encode_response( time_now, sync_result, requester.access_token_id, filter_collection