0
0
Fork 1
mirror of https://mau.dev/maunium/synapse.git synced 2024-12-14 10:03:47 +01:00

Merge pull request #3925 from matrix-org/erikj/fix_producers_unregistered

Fix spurious exceptions when client closes conncetion
This commit is contained in:
Richard van der Hoff 2018-09-25 11:52:06 +01:00 committed by GitHub
commit 94f7befc31
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 14 deletions

1
changelog.d/3925.misc Normal file
View file

@ -0,0 +1 @@
Fix spurious exceptions when remote http client closes conncetion

View file

@ -84,6 +84,17 @@ def wrap_json_request_handler(h):
logger.info(
"%s SynapseError: %s - %s", request, code, e.msg
)
# Only respond with an error response if we haven't already started
# writing, otherwise lets just kill the connection
if request.startedWriting:
if request.transport:
try:
request.transport.abortConnection()
except Exception:
# abortConnection throws if the connection is already closed
pass
else:
respond_with_json(
request, code, e.error_dict(), send_cors=True,
pretty_print=_request_user_agent_is_curl(request),
@ -100,6 +111,16 @@ def wrap_json_request_handler(h):
request,
f.getTraceback().rstrip(),
)
# Only respond with an error response if we haven't already started
# writing, otherwise lets just kill the connection
if request.startedWriting:
if request.transport:
try:
request.transport.abortConnection()
except Exception:
# abortConnection throws if the connection is already closed
pass
else:
respond_with_json(
request,
500,