diff --git a/src/tls_proxy.py b/src/tls_proxy.py index 4f40f30..fad757d 100644 --- a/src/tls_proxy.py +++ b/src/tls_proxy.py @@ -77,6 +77,12 @@ async def serve(routes): if peer: peer.close() def accept(reader, writer, route): + # connection_made calls this synchronously. Pause before scheduling the + # coroutine: otherwise StreamReader can consume ClientHello while that + # coroutine waits in the event-loop queue. start_tls resumes the transport + # after installing SSLProtocol. Outgoing local plaintext is unaffected. + if route['mode'] == 'server': + writer.transport.pause_reading() if len(tasks) >= 96: writer.close(); return task = asyncio.create_task(handle(reader, writer, route))