dbcli / mssql-cli

A command-line client for SQL Server with auto-completion and syntax highlighting
BSD 3-Clause "New" or "Revised" License
1.35k stars 191 forks source link

Infinte loop on remote connection #512

Open helvete opened 3 years ago

helvete commented 3 years ago

Since I reinstalled my system to Debian 10 I can no longer connect to a remote mssql server.

When I try to connect to a remote server the process never ends (and utilizes 100% of one CPU thread). It produces following trace if killed by ^C:

^CTraceback (most recent call last):
  File "/usr/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/main.py", line 122, in <module>
    main()
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/main.py", line 115, in main
    run_cli_with(mssqlcli_options)
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/main.py", line 52, in run_cli_with
    mssqlcli.connect_to_database()
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/mssql_cli.py", line 278, in connect_to_database
    owner_uri, error_messages = self.mssqlcliclient_main.connect_to_database()
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/mssqlcliclient.py", line 91, in connect_to_database
    owner_uri, error_messages = self._execute_connection_request_with(connection_params)
  File "/usr/local/lib/python3.7/dist-packages/mssqlcli/mssqlcliclient.py", line 188, in _execute_connection_request_with
    time.sleep(time_wait_if_no_response)
KeyboardInterrupt

It seems infinite loop is in progress here.

I tried mutliple versions of both python3 and python 2.7, all with the same result. Current versions:

I tried to install mssql-cli on the remote server and then I can connect normally. The same applies for local connections - these work OK as well.

The only specific I know of is that the remote server is only accessible via PPTP VPN. But this posed no problem before I reinstalled my system (it was Ubuntu 18.04).

Similarly I can connect to the remote database using all other means. For example, this simple script connects there OK as well:

#!/usr/bin/python3
import pymssql
conn = pymssql.connect(
        server='<server-ip>',
        user='<server-user>',
        password='<server-passwd>',
        database='<server-dbname>')
cursor = conn.cursor()
cursor.execute("""
        SELECT id
        FROM dbo.person
        ORDER BY person.id DESC
        ;""")
row = cursor.fetchone()
i = 0
while row:
    print(str(row[0]))
    row = cursor.fetchone()
    i += 1
    if i > 50:
        break

(This hints that neither the VPN nor particular OS or python versions are the cause of the problem IMHO)

I have searched the issues here (and using search engines) thoroughly but at no avail.

Please let me know if more debugging data have to be provided.

It is no april's fools joke :smiley:

amaturehr commented 2 years ago

I have run into the same problem after upgrading from Ubuntu 18.04 to 20.04. I have the same behavior of high CPU and a "hung" state.

I too can connect to this remote database using dbeaver-ce client with no issue. So there is no other connectivity issue happening. Even if I don't put in any credentials, just to expect to see a message saying so, it still just hangs.

I have tried uninstalling and re-installing mssql-cli via pip. I even tried to install it on another ubuntu 20.04 machine, where this was not previously installed, and I got the same behavior.

When I ctrl+C out of the hung state it shows similar to @helvete


  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "~/.local/lib/python3.8/site-packages/mssqlcli/main.py", line 122, in <module>
    main()
  File "~/.local/lib/python3.8/site-packages/mssqlcli/main.py", line 115, in main
    run_cli_with(mssqlcli_options)
  File "~/.local/lib/python3.8/site-packages/mssqlcli/main.py", line 52, in run_cli_with
    mssqlcli.connect_to_database()
  File "~/.local/lib/python3.8/site-packages/mssqlcli/mssql_cli.py", line 278, in connect_to_database
    owner_uri, error_messages = self.mssqlcliclient_main.connect_to_database()
  File "~/.local/lib/python3.8/site-packages/mssqlcli/mssqlcliclient.py", line 91, in connect_to_database
    owner_uri, error_messages = self._execute_connection_request_with(connection_params)
  File "~/.local/lib/python3.8/site-packages/mssqlcli/mssqlcliclient.py", line 188, in _execute_connection_request_with
    time.sleep(time_wait_if_no_response)
KeyboardInterrupt
^C