Ticket #3420: persistent_connection_no_leak.diff

File persistent_connection_no_leak.diff, 1.1 KB (added by zaheerm, 6 years ago)

fix to leaking protocols

  • twisted/web/client.py

     
    785785        """
    786786        protos = self._protocolCache.setdefault((scheme, host, port), [])
    787787        maybeDisconnected = False
    788         while protos:
    789             # connection exists
    790             p = protos.pop(0)
     788        d = None
     789        for p in protos:
    791790            if p.state == 'QUIESCENT':
     791                # available existing connection
    792792                d = defer.succeed(p)
    793793                maybeDisconnected = True
    794794                break
    795         else:
     795        if not d:
    796796            # new connection
    797797            d = self._connect(scheme, host, port)
    798798        req = Request(method, path, headers, bodyProducer,
    799799                      persistent=self.persistent)
    800800
    801801        def saveProtocol(response, proto):
    802             if self.persistent:
     802            if self.persistent and proto not in protos:
    803803                protos.append(proto)
    804804            return response
    805805