From 991af12fcb498928a6fdd5bfc96caa8f54ed70b1 Mon Sep 17 00:00:00 2001 From: Fabio Zadrozny Date: Thu, 10 Dec 2020 09:01:11 -0300 Subject: [PATCH] Handle invalid socket options. Fixes #491 --- .../pydevd/_pydevd_bundle/pydevd_comm.py | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py index 83ced4493..511a5dd23 100644 --- a/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py +++ b/src/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py @@ -441,18 +441,20 @@ def start_client(host, port): # then sends a keepalive ping once every 3 seconds (TCP_KEEPINTVL), # and closes the connection after 5 failed ping (TCP_KEEPCNT), or 15 seconds try: - IPPROTO_TCP, SO_KEEPALIVE, TCP_KEEPIDLE, TCP_KEEPINTVL, TCP_KEEPCNT = ( - socket_module.IPPROTO_TCP, - socket_module.SO_KEEPALIVE, - socket_module.TCP_KEEPIDLE, - socket_module.TCP_KEEPINTVL, - socket_module.TCP_KEEPCNT, - ) - s.setsockopt(SOL_SOCKET, SO_KEEPALIVE, 1) - s.setsockopt(IPPROTO_TCP, TCP_KEEPIDLE, 1) - s.setsockopt(IPPROTO_TCP, TCP_KEEPINTVL, 3) - s.setsockopt(IPPROTO_TCP, TCP_KEEPCNT, 5) - except AttributeError: + s.setsockopt(SOL_SOCKET, socket_module.SO_KEEPALIVE, 1) + except (AttributeError, OSError): + pass # May not be available everywhere. + try : + s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_KEEPIDLE, 1) + except (AttributeError, OSError): + pass # May not be available everywhere. + try: + s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_KEEPINTVL, 3) + except (AttributeError, OSError): + pass # May not be available everywhere. + try: + s.setsockopt(socket_module.IPPROTO_TCP, socket_module.TCP_KEEPCNT, 5) + except (AttributeError, OSError): pass # May not be available everywhere. try: