From 3bb93556628d71d9d44a7529a0bdee2ff84a7dcb Mon Sep 17 00:00:00 2001 From: Vangelis Banos Date: Fri, 2 Mar 2018 13:26:26 +0000 Subject: [PATCH] Extra connection evaluation before putting it back to the pool Use `urllib3.util.is_connection_dropped` to check that the connection is fine before putting it back to the pool to be reused later. --- warcprox/mitmproxy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/warcprox/mitmproxy.py b/warcprox/mitmproxy.py index 6cf12dc..c75c1e2 100644 --- a/warcprox/mitmproxy.py +++ b/warcprox/mitmproxy.py @@ -64,6 +64,7 @@ import urlcanon import time import collections import cProfile +from urllib3.util import is_connection_dropped class ProxyingRecorder(object): """ @@ -456,7 +457,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler): # put it back in the pool to reuse it later. if prox_rec_res: prox_rec_res.close() - if connection_is_fine: + if connection_is_fine and not is_connection_dropped(self._remote_server_conn): self._conn_pool._put_conn(self._remote_server_conn) else: self._remote_server_conn.sock.close()