snuba icon indicating copy to clipboard operation
snuba copied to clipboard

Connecting to ClickHouse with SSL Port: Unexpected Packet from Server

Open patsevanton opened this issue 1 year ago • 2 comments

Title: Error Connecting to ClickHouse with SSL Port: Unexpected Packet from Server

Description:

When attempting to connect to ClickHouse using the SSL port (e.g., 9440), the Snuba project throws an error indicating an unexpected packet from the server. This issue occurs during the migration process when Snuba tries to execute a query to check the ClickHouse connection.

Steps to Reproduce:

  1. Set up Snuba with a ClickHouse instance configured to use SSL on port 9440.
  2. Run the migration command:
    snuba migrations migrate --force
    
  3. Observe the following error:
    snuba.clickhouse.errors.ClickhouseError: Unexpected packet from server clickhouse-server:9440 (expected Hello or Exception, got Unknown packet)
    

Expected Behavior:

Snuba should successfully connect to ClickHouse using the SSL port and proceed with the migration process.

Actual Behavior:

The following error is thrown:

snuba.clickhouse.errors.ClickhouseError: Unexpected packet from server clickhouse-server:9440 (expected Hello or Exception, got Unknown packet)

Suggested Fix:

It appears that Snuba might not be handling the SSL connection properly, leading to the unexpected packet error. A potential fix could involve ensuring that the SSL configuration is correctly passed to the ClickHouse client and that the client is properly initialized for SSL connections.

Related PR:

  • #2018
  • #2033
  • #6459

Logs:

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/bin/snuba", line 33, in <module>
    sys.exit(load_entry_point('snuba', 'console_scripts', 'snuba')())
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/snuba/snuba/cli/migrations.py", line 107, in migrate
    check_clickhouse_connections(clusters_to_check)
  File "/usr/src/snuba/snuba/migrations/connect.py", line 90, in check_clickhouse_connections
    check_clickhouse(clickhouse)
  File "/usr/src/snuba/snuba/migrations/connect.py", line 112, in check_clickhouse
    ver = clickhouse.execute("SELECT version()").results[0][0]
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/snuba/snuba/clickhouse/native.py", line 285, in execute
    raise ClickhouseError(e.message, code=e.code) from e
snuba.clickhouse.errors.ClickhouseError: Unexpected packet from server clickhouse-server:9440 (expected Hello or Exception, got Unknown packet)
Error in install/bootstrap-snuba.sh:4.
'$dcr snuba-api migrations migrate --force' exited with status 1
-> ./install.sh:main:35
--> install/bootstrap-snuba.sh:source:4

install/error-handling.sh: line 82: /usr/bin/docker: Argument list too long

patsevanton avatar Oct 27 '24 13:10 patsevanton

small hotfix https://github.com/getsentry/snuba/pull/6794

zhenyatsk avatar Jan 20 '25 17:01 zhenyatsk

Also there is another problem with SSL in rust part: https://github.com/getsentry/snuba/blob/89ff716464882656fa548e39a412d32613e8026a/rust_snuba/src/mutations/clickhouse.rs#L48 Maybe you need to change schema from http to https in case of secure connection: let url = format!("http://{hostname}:{http_port}");

LimeBeck avatar Apr 03 '25 12:04 LimeBeck