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

Fix possible segfault in PostgreSQLSource #57567

Merged
merged 5 commits into from Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Processors/Sources/PostgreSQLSource.cpp
Expand Up @@ -199,7 +199,8 @@ PostgreSQLSource<T>::~PostgreSQLSource()
tryLogCurrentException(__PRETTY_FUNCTION__);
}

connection_holder->setBroken();
if (connection_holder)
connection_holder->setBroken();
}
}

Expand Down
Expand Up @@ -839,6 +839,34 @@ def test_bad_connection_options(started_cluster):
pg_manager.drop_materialized_db("test_database")


def test_failed_load_from_snapshot(started_cluster):
if instance.is_built_with_sanitizer() or instance.is_debug_build():
pytest.skip(
"Sanitizers and debug mode are skipped, because this test thrown logical error"
)

table = "failed_load"

pg_manager.create_postgres_table(
table,
template="""
CREATE TABLE IF NOT EXISTS "{}" (
key text NOT NULL, value text[], PRIMARY KEY(key))
""",
)
instance.query(
f"INSERT INTO postgres_database.{table} SELECT number, [1, 2] from numbers(0, 1000000)"
)

# Create a table with wrong table structure
assert "Could not convert string to i" in instance.query_and_get_error(
f"""
SET allow_experimental_materialized_postgresql_table=1;
CREATE TABLE {table} (a Int32, b Int32) ENGINE=MaterializedPostgreSQL('{started_cluster.postgres_ip}:{started_cluster.postgres_port}', 'postgres_database', '{table}', 'postgres', 'mysecretpassword') ORDER BY a
"""
)


if __name__ == "__main__":
cluster.start()
input("Cluster created, press any key to destroy...")
Expand Down