tm1py icon indicating copy to clipboard operation
tm1py copied to clipboard

TCP KEEPALIVE does not work on MacOS

Open rclapp opened this issue 11 months ago • 2 comments

When enabling TCP Keep Alive on MacOS connection fails on line 476


            socket_options = urllib3.connection.HTTPConnection.default_socket_options + [
                (socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1),
                (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, self.TCP_SOCKET_OPTIONS['TCP_KEEPIDLE']),
                (socket.IPPROTO_TCP, socket.TCP_KEEPINTVL, self.TCP_SOCKET_OPTIONS['TCP_KEEPINTVL']),
                (socket.IPPROTO_TCP, socket.TCP_KEEPCNT, self.TCP_SOCKET_OPTIONS['TCP_KEEPCNT'])]

Based on this documentation some socket options are only valid on windows.

https://docs.python.org/3.7/library/socket.html#:~:text=On%20Windows%2C%20TCP_KEEPIDLE%2C%20TCP_KEEPINTVL%20appear%20if%20run%2Dtime%20Windows%20supports.

rclapp avatar Mar 13 '24 19:03 rclapp

Could you describe how you got into this issue? I tested it on MacOS and it worked fine.

macsir avatar Mar 14 '24 03:03 macsir

Python 3.10

[tm1srv01]
address=
instance=
database=tm1-testing
application_client_id=
application_client_secret=
user=test-user
ssl=False
async_requests_mode=False
timeout=6000
tcp_keepalive=True
config = configparser.ConfigParser()
config.read(Path(__file__).parent.joinpath('config.ini'))
with TM1Service(**config['tm1srv01']) as tm1:
    print(f"Ready: {tm1.connection.session_id}")
    pass
Traceback (most recent call last):
  File "/Users/rdclapp/Applications/PyCharm Professional.app/Contents/plugins/python/helpers/pydev/pydevd.py", line 1534, in _exec
    pydev_imports.execfile(file, globals, locals)  # execute the script
  File "/Users/rdclapp/Applications/PyCharm Professional.app/Contents/plugins/python/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
    exec(compile(contents+"\n", file, 'exec'), glob, loc)
  File "/Users/rdclapp/Library/Application Support/JetBrains/PyCharm2023.3/scratches/tm1-manager.py", line 15, in <module>
    with TM1Service(**config['tm1srv01']) as tm1:
  File "/Users/rdclapp/workspaces/public git/TM1py/TM1py/Services/TM1Service.py", line 66, in __init__
    self._tm1_rest = RestService(**kwargs)
  File "/Users/rdclapp/workspaces/public git/TM1py/TM1py/Services/RestService.py", line 205, in __init__
    self._manage_http_adapter()
  File "/Users/rdclapp/workspaces/public git/TM1py/TM1py/Services/RestService.py", line 476, in _manage_http_adapter
    (socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, self.TCP_SOCKET_OPTIONS['TCP_KEEPIDLE']),
AttributeError: module 'socket' has no attribute 'TCP_KEEPIDLE'. Did you mean: 'TCP_KEEPALIVE'?

rclapp avatar Mar 14 '24 14:03 rclapp

My apology. I can reproduce this issue and it works initially after replacing TCP_KEEPALIVE with TCP_KEEPIDLE for MacOS. However, after testing some long-run process in the OpenShift cluster. It is facing 60s closed connection error still even with TCP_KEEPALIVE enabled.

requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))

After searching, it might be caused by Route timeout configuration does not work properly in OCP 4, OSD and ROSA To make it simple, I think the most appropriate and reliable way is still to use async_requests_mode parameter going forward in cloud environments for long-run requests. Let me create a PR to remove this tcp_keepalive parameter. Thanks.

macsir avatar Mar 16 '24 12:03 macsir

Funny you found that, I was actually testing v12 on OpenShift as a part of these tests. PA support was trying to figure out why timeouts were not being respected. Weird thing, is that even with the proper annotations those errors still show up. I will share that link with IBM PA regardless

rclapp avatar Mar 18 '24 14:03 rclapp

solved with #1077

MariusWirtz avatar Apr 03 '24 13:04 MariusWirtz