Skip to content

Commit 41b04b0

Browse files
committed
fix tls proxy due to select only affecting underlying socket
1 parent 49b2465 commit 41b04b0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

localstack/utils/server/proxy_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
LOG = logging.getLogger(__name__)
1818

1919
BUFFER_SIZE = 2**10 # 1024
20+
TLS_BUFFER_SIZE = 16384 # 16 KB, max TLS record size
2021

2122
PortOrUrl = Union[str, int]
2223

@@ -140,7 +141,7 @@ def _handle_socket(self, source_socket: ssl.SSLSocket, client_address: str) -> N
140141
s_read, _, _ = select.select(sockets, [], [])
141142

142143
for s in s_read:
143-
data = s.recv(BUFFER_SIZE)
144+
data = s.recv(TLS_BUFFER_SIZE)
144145
if not data:
145146
return
146147

@@ -152,6 +153,9 @@ def _handle_socket(self, source_socket: ssl.SSLSocket, client_address: str) -> N
152153
LOG.warning(
153154
"Error while proxying SSL request: %s", e, exc_info=LOG.isEnabledFor(logging.DEBUG)
154155
)
156+
finally:
157+
source_socket.close()
158+
LOG.debug("Connection finished!")
155159

156160
def do_run(self):
157161
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
@@ -168,6 +172,8 @@ def do_run(self):
168172
try:
169173
conn, addr = ssock.accept()
170174
self.thread_pool.submit(self._handle_socket, conn, addr)
175+
except ssl.SSLZeroReturnError:
176+
pass
171177
except Exception as e:
172178
LOG.exception("Error accepting socket: %s", e)
173179

0 commit comments

Comments
 (0)