From da42e98bf80f22747089946a6a08840e0bf646a9 Mon Sep 17 00:00:00 2001 From: Miguel Grinberg Date: Sun, 13 Aug 2023 14:59:21 +0100 Subject: [PATCH] Do not duplicate SSLSocket instances (Fixes #26) --- src/simple_websocket/ws.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/simple_websocket/ws.py b/src/simple_websocket/ws.py index ce4af91..21dc7a2 100644 --- a/src/simple_websocket/ws.py +++ b/src/simple_websocket/ws.py @@ -313,7 +313,11 @@ def __init__(self, environ, subprotocols=None, receive_bytes=4096, if not hasattr(wsgi_input, 'raw') and hasattr(wsgi_input, 'rfile'): wsgi_input = wsgi_input.rfile if hasattr(wsgi_input, 'raw'): - sock = wsgi_input.raw._sock.dup() + sock = wsgi_input.raw._sock + try: + sock = sock.dup() + except NotImplementedError: + pass self.mode = 'gevent' if sock is None: raise RuntimeError('Cannot obtain socket from WSGI environment.')