Skip to content

Commit 3a30846

Browse files
authored
Fix mypy on latest Twisted release (#17036)
`ITransport.abortConnection` isn't a thing, but `HTTPChannel.forceAbortClient` calls it, so lets just use that Fixes #16728
1 parent db4e321 commit 3a30846

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

changelog.d/17036.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix mypy with latest Twisted release.

synapse/http/proxy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ def connectionLost(self, reason: Failure = connectionDone) -> None:
262262
self._request.finish()
263263
else:
264264
# Abort the underlying request since our remote request also failed.
265-
self._request.transport.abortConnection()
265+
if self._request.channel:
266+
self._request.channel.forceAbortClient()
266267

267268

268269
class ProxySite(Site):

synapse/http/server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def return_json_error(
153153
# Only respond with an error response if we haven't already started writing,
154154
# otherwise lets just kill the connection
155155
if request.startedWriting:
156-
if request.transport:
156+
if request.channel:
157157
try:
158-
request.transport.abortConnection()
158+
request.channel.forceAbortClient()
159159
except Exception:
160160
# abortConnection throws if the connection is already closed
161161
pass

synapse/http/site.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def handleContentChunk(self, data: bytes) -> None:
150150
self.get_method(),
151151
self.get_redacted_uri(),
152152
)
153-
self.transport.abortConnection()
153+
if self.channel:
154+
self.channel.forceAbortClient()
154155
return
155156
super().handleContentChunk(data)
156157

0 commit comments

Comments
 (0)