Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle SSL_WANT_READ/WRITE errors #619

Merged
merged 1 commit into from
Jun 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import random
import select
import socket
import ssl
import sys
import time

Expand Down Expand Up @@ -247,7 +248,14 @@ def _read(self, length, timeout):
# have to check wlist and xlist as we don't set any
raise self.handler.timeout_exception(
"socket time-out during read")
chunk = self._socket.recv(remaining)
try:
chunk = self._socket.recv(remaining)
except ssl.SSLError as e:
if e.errno in (ssl.SSL_ERROR_WANT_READ,
ssl.SSL_ERROR_WANT_WRITE):
ceache marked this conversation as resolved.
Show resolved Hide resolved
continue
else:
raise
if chunk == b'':
raise ConnectionDropped('socket connection broken')
msgparts.append(chunk)
Expand Down Expand Up @@ -319,7 +327,14 @@ def _write(self, msg, timeout):
raise self.handler.timeout_exception("socket time-out"
" during write")
msg_slice = buffer(msg, sent)
bytes_sent = self._socket.send(msg_slice)
try:
bytes_sent = self._socket.send(msg_slice)
except ssl.SSLError as e:
if e.errno in (ssl.SSL_ERROR_WANT_READ,
ceache marked this conversation as resolved.
Show resolved Hide resolved
ssl.SSL_ERROR_WANT_WRITE):
continue
else:
raise
if not bytes_sent:
raise ConnectionDropped('socket connection broken')
sent += bytes_sent
Expand Down