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

secure_server example causes psql and pgcli to segfault #154

Open
samuelcolvin opened this issue Jan 31, 2024 · 6 comments
Open

secure_server example causes psql and pgcli to segfault #154

samuelcolvin opened this issue Jan 31, 2024 · 6 comments

Comments

@samuelcolvin
Copy link

I'm on main, currently 30707e1, I can run the secure_server example with

cargo r --example secure_server

Then try to connect with psql, and I get the following:

➤ psql -p 5433 -U postgres -h 127.0.0.1                
psql (14.9 (Homebrew), server 0.19.2)
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, bits: 256, compression: off)
Type "help" for help.

zsh: segmentation fault  psql -p 5433 -U postgres -h 127.0.0.1

Similarly if I try to connect with pgcli, I get:

➤ pgcli 'postgresql://postgres:postgres@127.0.0.1:5433'
Server: PostgreSQL 0.19.2
Version: 4.0.1
Home: http://pgcli.com
postgres@127:(none)> Exception in thread completion_refresh:
Traceback (most recent call last):
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/threading.py", line 953, in runreshing completions...                                                                                  
    self._target(*self._args, **self._kwargs)
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pgcli/completion_refresher.py", line 67, in _bg_refresh
    refresher(completer, executor)
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pgcli/completion_refresher.py", line 108, in refresh_schemata
    completer.set_search_path(executor.search_path())
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pgcli/pgcompleter.py", line 328, in set_search_path
    self.search_path = self.escaped_names(search_path)
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/pgcli/pgcompleter.py", line 176, in escaped_names
    return [self.escape_name(name) for name in names]
TypeError: 'int' object is not iterable
Exception ignored in: <function BaseConnection.__del__ at 0x1063d4e50>
Traceback (most recent call last):
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/psycopg/connection.py", line 158, in __del__
    f"connection {self} was deleted while still open."
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/psycopg/connection.py", line 165, in __repr__
    info = connection_summary(self.pgconn)
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/psycopg/pq/misc.py", line 136, in connection_summary
    if pgconn.user != pgconn.db:
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/psycopg/pq/pq_ctypes.py", line 177, in user
    return self._call_bytes(impl.PQuser)
  File "/Users/samuel/.pyenv/versions/3.10.13/lib/python3.10/site-packages/psycopg/pq/pq_ctypes.py", line 711, in _call_bytes
    assert rv is not None
AssertionError: 
python(40911,0x16c24f000) malloc: double free for ptr 0x109810400
python(40911,0x16c24f000) malloc: *** set a breakpoint in malloc_error_break to debug
zsh: abort      pgcli 'postgresql://postgres:postgres@127.0.0.1:5433'

I'm not quite sure what's causing this behavior, or what to try next, but I thought it would be worthwhile reporting the issue.

@sunng87
Copy link
Owner

sunng87 commented Jan 31, 2024

hi @samuelcolvin , thank you for reporting. I just reproduced this issue from my local environment. It's because pgcli sends sql query SELECT * FROM current_schemas(true) on startup to get schema list for its completion feature. However, as an example of this wire protocol library, this server doesn't cover sql parsing and schema resolution. It always returns fixed resultset

+----+--------+
| id | name   |
|----+--------|
| 0  | Tom    |
| 1  | Jerry  |
| 2  | <null> |
+----+--------+

So it's unexpected for pgcli and the error is thrown. But it doesn't block you from further usage of pgcli and pgwire example.

@samuelcolvin
Copy link
Author

Thanks, what about the segmentation fault from psql? I believe psql doesn't issue any queries on connection.

@samuelcolvin
Copy link
Author

To be clear, I don't think the error is just from the unexpected query response - I've seen that too and it causes python exceptions. But not errors in the C code, also it doesn't explain the error from psql.

@sunng87
Copy link
Owner

sunng87 commented Feb 5, 2024

That's weird I cannot reproduce it with psql 16.1 on archlinux.

psql -h 127.0.0.1 -p 5433   
psql (16.1, server 0.19.2)
WARNING: psql major version 16, server major version 0.19.
         Some psql features might not work.
SSL connection (protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384, compression: off)
Type "help" for help.

sunng=>

@sunng87
Copy link
Owner

sunng87 commented Feb 5, 2024

And off-topic, I'm curious that are you investigating pgwire for some new idea/project?

@sunng87
Copy link
Owner

sunng87 commented Mar 28, 2024

For the psql issue, I found it's an issue that can only reproduce on psql 14.x client compiled for homebrew.

psql: error: connection to server at “5s0kjjpih6a0.us-west-2.aws.greptime.cloud” (52.25.118.248), port 4003 failed: FATAL:  Database not specified
connection to server at “5s0kjjpih6a0.us-west-2.aws.greptime.cloud” (52.25.118.248), port 4003 failed: FATAL:  Database not specified
psql(33257,0x1de8e1000) malloc: double free for ptr 0x153808200
psql(33257,0x1de8e1000) malloc: *** set a breakpoint in malloc_error_break to debug

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