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

Commit

Permalink
Merge pull request #3925 from matrix-org/erikj/fix_producers_unregist…
Browse files Browse the repository at this point in the history
…ered

Fix spurious exceptions when client closes conncetion
  • Loading branch information
richvdh authored Sep 25, 2018
2 parents e4e9648 + 13f6f16 commit 94f7bef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
1 change: 1 addition & 0 deletions changelog.d/3925.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix spurious exceptions when remote http client closes conncetion
49 changes: 35 additions & 14 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,21 @@ def wrapped_request_handler(self, request):
logger.info(
"%s SynapseError: %s - %s", request, code, e.msg
)
respond_with_json(
request, code, e.error_dict(), send_cors=True,
pretty_print=_request_user_agent_is_curl(request),
)

# 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),
)

except Exception:
# failure.Failure() fishes the original Failure out
Expand All @@ -100,16 +111,26 @@ def wrapped_request_handler(self, request):
request,
f.getTraceback().rstrip(),
)
respond_with_json(
request,
500,
{
"error": "Internal server error",
"errcode": Codes.UNKNOWN,
},
send_cors=True,
pretty_print=_request_user_agent_is_curl(request),
)
# 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,
{
"error": "Internal server error",
"errcode": Codes.UNKNOWN,
},
send_cors=True,
pretty_print=_request_user_agent_is_curl(request),
)

return wrap_async_request_handler(wrapped_request_handler)

Expand Down

0 comments on commit 94f7bef

Please sign in to comment.