|
9 | 9 | import h2.events
|
10 | 10 | import h2.settings
|
11 | 11 |
|
| 12 | +from ..compat import ssl |
12 | 13 | from ..tls import wrap_socket, H2_NPN_PROTOCOLS, H2C_PROTOCOL
|
13 | 14 | from ..common.exceptions import ConnectionResetError
|
14 | 15 | from ..common.bufsocket import BufferedSocket
|
@@ -237,7 +238,7 @@ def connect(self):
|
237 | 238 | host = self.proxy_host
|
238 | 239 | port = self.proxy_port
|
239 | 240 |
|
240 |
| - sock = socket.create_connection((host, port), 5) |
| 241 | + sock = socket.create_connection((host, port)) |
241 | 242 |
|
242 | 243 | if self.secure:
|
243 | 244 | assert not self.proxy_host, "Using a proxy with HTTPS not yet supported."
|
@@ -522,13 +523,31 @@ def _recv_cb(self):
|
522 | 523 | # TODO: Re-evaluate this.
|
523 | 524 | self._single_read()
|
524 | 525 | count = 9
|
| 526 | + retry_wait = 0.05 # can improve responsiveness to delay the retry |
525 | 527 |
|
526 | 528 | while count and self._sock is not None and self._sock.can_read:
|
527 |
| - # If the connection has been closed, bail out. |
| 529 | + # If the connection has been closed, bail out, but retry |
| 530 | + # on transient errors. |
528 | 531 | try:
|
529 | 532 | self._single_read()
|
530 | 533 | except ConnectionResetError:
|
531 | 534 | break
|
| 535 | + except ssl.SSLError as e: # pragma: no cover |
| 536 | + # these are transient errors that can occur while reading from |
| 537 | + # ssl connections. |
| 538 | + if e.args[0] in (ssl.SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE): |
| 539 | + continue |
| 540 | + else: |
| 541 | + raise |
| 542 | + except socket.error as e: # pragma: no cover |
| 543 | + if e.errno in (errno.EINTR, errno.EAGAIN): |
| 544 | + # if 'interrupted' or 'try again', continue |
| 545 | + sleep(retry_wait) |
| 546 | + continue |
| 547 | + elif e.errno == errno.ECONNRESET: |
| 548 | + break |
| 549 | + else: |
| 550 | + raise |
532 | 551 |
|
533 | 552 | count -= 1
|
534 | 553 |
|
|
0 commit comments