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 #870 from matrix-org/rav/work_around_tls_bug
Browse files Browse the repository at this point in the history
Work around TLS bug in twisted
  • Loading branch information
richvdh authored Jun 15, 2016
2 parents d9f7fa2 + 255c229 commit 15bf3e3
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions synapse/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@

from canonicaljson import encode_canonical_json

from twisted.internet import defer, reactor, ssl, protocol
from twisted.internet import defer, reactor, ssl, protocol, task
from twisted.internet.endpoints import SSL4ClientEndpoint, TCP4ClientEndpoint
from twisted.web.client import (
BrowserLikeRedirectAgent, ContentDecoderAgent, GzipDecoder, Agent,
readBody, FileBodyProducer, PartialDownloadError,
readBody, PartialDownloadError,
)
from twisted.web.client import FileBodyProducer as TwistedFileBodyProducer
from twisted.web.http import PotentialDataLoss
from twisted.web.http_headers import Headers
from twisted.web._newclient import ResponseDone
Expand Down Expand Up @@ -468,3 +469,26 @@ def getContext(self, hostname=None, port=None):

def creatorForNetloc(self, hostname, port):
return self


class FileBodyProducer(TwistedFileBodyProducer):
"""Workaround for https://twistedmatrix.com/trac/ticket/8473
We override the pauseProducing and resumeProducing methods in twisted's
FileBodyProducer so that they do not raise exceptions if the task has
already completed.
"""

def pauseProducing(self):
try:
super(FileBodyProducer, self).pauseProducing()
except task.TaskDone:
# task has already completed
pass

def resumeProducing(self):
try:
super(FileBodyProducer, self).resumeProducing()
except task.NotPaused:
# task was not paused (probably because it had already completed)
pass

0 comments on commit 15bf3e3

Please sign in to comment.