Long response time when calling unmatched requests
kob-aha opened this issue · comments
I'm using HTTPretty while setting 'allow_net_connect=true' when calling 'enable'. The problem is that when I call an unmatched URL it is forwarded to the real endpoint, however the response time is very long (about 1 sec).
I tried to debug it a little and it seems like HTTPretty uses the real socket and gets a response relatively fast, however it then keeps waiting on the socket for up to a second.
This is the relevant code from real_sendall in core.py:
should_continue = True
while should_continue:
try:
received = sock.recv(self._bufsize)
self.fd.write(received)
should_continue = bool(received.strip())
except socket.error as e:
if e.errno == EAGAIN:
continue
break
I see that it gets a response in a few ms and then simply gets stuck on sock.recv usually up to a second until it gets an empty data and exit.
I tested it with different URLs and got the same behavior.