Skip to content

Commit

Permalink
Fix mypy on latest Twisted release (#17036)
Browse files Browse the repository at this point in the history
`ITransport.abortConnection` isn't a thing, but
`HTTPChannel.forceAbortClient` calls it, so lets just use that

Fixes #16728
  • Loading branch information
erikjohnston authored Apr 11, 2024
1 parent db4e321 commit 3a30846
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/17036.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix mypy with latest Twisted release.
3 changes: 2 additions & 1 deletion synapse/http/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,8 @@ def connectionLost(self, reason: Failure = connectionDone) -> None:
self._request.finish()
else:
# Abort the underlying request since our remote request also failed.
self._request.transport.abortConnection()
if self._request.channel:
self._request.channel.forceAbortClient()


class ProxySite(Site):
Expand Down
4 changes: 2 additions & 2 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ def return_json_error(
# 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:
if request.channel:
try:
request.transport.abortConnection()
request.channel.forceAbortClient()
except Exception:
# abortConnection throws if the connection is already closed
pass
Expand Down
3 changes: 2 additions & 1 deletion synapse/http/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ def handleContentChunk(self, data: bytes) -> None:
self.get_method(),
self.get_redacted_uri(),
)
self.transport.abortConnection()
if self.channel:
self.channel.forceAbortClient()
return
super().handleContentChunk(data)

Expand Down

0 comments on commit 3a30846

Please sign in to comment.