Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two issues on default TrueNAS SCALE from macOS client #13

Open
ivan98 opened this issue Oct 31, 2024 · 1 comment
Open

Two issues on default TrueNAS SCALE from macOS client #13

ivan98 opened this issue Oct 31, 2024 · 1 comment

Comments

@ivan98
Copy link

ivan98 commented Oct 31, 2024

I've a simple script like this running on my macOS laptop, against a TrueNAS SCALE 24.10 destination.

from truenas_api_client import Client

with Client(uri="ws://FQDN/websocket") as c:
    c.call("auth.login_with_api_key", key)
    dat = c.call("system.info")

Issue 1

Running this script gives:

(venv) ivanl@ilmac1513 truenas % ./test.py
Websocket client error: ValueError('scheme https is invalid')
Traceback (most recent call last):
  File "/Users/ivanl/Documents/src/truenas/./test.py", line 16, in <module>
    with Client(uri="ws://FQDN/websocket") as c:
         ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/__init__.py", line 93, in __init__
    self.__client = client_class(uri, reserved_ports, py_exceptions, log_py_exceptions, call_timeout, verify_ssl)
                    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 230, in __init__
    raise ClientException(self._connection_error)
truenas_api_client.exc.ClientException: WebSocket connection closed with code=None, reason=None

This is traced to the "Web Interface HTTP -> HTTPS Redirect" setting in TrueNAS UI. By default, this is enabled which causes ws: to be redirected to https which confuses middleware at port 6000.

Issue 2

Once the setting "Web Interface HTTP -> HTTPS Redirect" is disabled, the error msg changes to:

(venv) ivanl@ilmac1513 truenas % ./test.py
Websocket client error: AttributeError("module 'socket' has no attribute 'TCP_KEEPIDLE'")
Traceback (most recent call last):
  File "/Users/ivanl/Documents/src/truenas/./test.py", line 16, in <module>
    with Client(uri="ws://FQDN/websocket") as c:
         ~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/__init__.py", line 93, in __init__
    self.__client = client_class(uri, reserved_ports, py_exceptions, log_py_exceptions, call_timeout, verify_ssl)
                    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 225, in __init__
    self._ws.connect()
    ~~~~~~~~~~~~~~~~^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/truenas_api_client/legacy.py", line 60, in connect
    self.socket = connect(self.url, sockopt, proxy_info(), None)[0]
                  ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 145, in connect
    sock = _open_socket(addrinfo_list, options.sockopt, options.timeout)
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 222, in _open_socket
    raise error
  File "/Users/ivanl/Documents/src/truenas/venv.nosync/lib/python3.13/site-packages/websocket/_http.py", line 209, in _open_socket
    sock.connect(address)
    ~~~~~~~~~~~~^^^^^^^^^
TimeoutError: timed out

macOS do not use TCP_KEEPIDLE like in Linux; instead it uses TCP_KEEPALIVE. Hence it works if line 119 in truenas_api_client/legacy.py is changed from

self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPIDLE, 1)
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_KEEPALIVE, 1)
@yocalebo
Copy link
Contributor

Thanks for the report! I fixed Issue 2 in #21. Issue 1 will be a bit more involved. Will fix that in a separate PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants