Skip to content

Segfault caused by outputstream being null. #335

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

Closed
rtcote opened this issue Sep 27, 2023 · 4 comments · Fixed by #336
Closed

Segfault caused by outputstream being null. #335

rtcote opened this issue Sep 27, 2023 · 4 comments · Fixed by #336
Labels
bug Something isn't working priority-high Pretty important bug or issue

Comments

@rtcote
Copy link
Contributor

rtcote commented Sep 27, 2023

It appears that the output stream is getting set to a nullptr. Was running v2.5.0 of the client. When I rolled-back to v2.4.0 of the client, the issue is no longer present. This issue shows up the first time I call Client::Insert() for each client instance. It's not clear what I am doing on the application side to cause this. Any thoughts as to how I can debug this?

My client is configured in the following manner:

m_client = std::make_shared<clickhouse::Client>(
    clickhouse::ClientOptions().SetHost(host)                                                                           // a hostname
                               .SetPingBeforeQuery(client_config.ping_before_query)                                     // true
                               .SetSendRetries(client_config.send_retries)                                              // 0
                               .SetCompressionMethod(compression_method)                                                // None
                               .SetRetryTimeout(std::chrono::seconds(client_config.retry_timeout_sec))                  // 0
                               .TcpKeepAlive(client_config.tcp_keep_alive)                                              // true
                               .SetConnectionConnectTimeout(std::chrono::seconds(client_config.connect_timeout_sec))    // 5
                               .SetConnectionRecvTimeout(std::chrono::milliseconds(client_config.recv_timeout_ms))      // 1000000
                               .SetConnectionSendTimeout(std::chrono::milliseconds(client_config.send_timeout_ms))      //  60000
                               );

Stack trace and gdb debugging

Thread 5 "rte-worker-8" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fffc5c87000 (LWP 136)]
clickhouse::WireFormat::WriteAll (output=..., buf=<optimized out>, len=1) at /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp:36
36      /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp: No such file or directory.
(gdb) bt
#0  clickhouse::WireFormat::WriteAll (output=..., buf=<optimized out>, len=1) at /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp:36
#1  0x0000555559dce5c1 in clickhouse::WireFormat::WriteVarint64 (output=..., value=<optimized out>, value@entry=1) at /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp:86
#2  0x0000555559dc7fcf in clickhouse::WireFormat::WriteUInt64 (value=1, output=...) at /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.h:74
#3  clickhouse::Client::Impl::SendQuery (this=0x7fffb8001460, query=...) at /git/submodules/clickhouse-cpp/clickhouse/client.cpp:720
#4  0x0000555559dc9477 in clickhouse::Client::Impl::Insert (this=0x7fffb8001460, table_name=..., query_id="", block=...) at /git/submodules/clickhouse-cpp/clickhouse/client.cpp:311

(gdb) frame 0
#0  clickhouse::WireFormat::WriteAll (output=..., buf=<optimized out>, len=1) at /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp:36
36      /git/submodules/clickhouse-cpp/clickhouse/base/wire_format.cpp: No such file or directory.
(gdb) info locals
original_len = 1
p = 0x7fffc5c2cb9e "\001"
written_previously = 1
(gdb) p output
$4 = (clickhouse::OutputStream &) <error reading variable>
(gdb) p &output
$5 = (clickhouse::OutputStream *) 0x0
@Enmk
Copy link
Contributor

Enmk commented Sep 27, 2023

Hi @rtcote ! Thank you for a report, investigating. In the mean time, could you please provide a minimal viable example of the query that causes this?

Also, please provide the following deatils:

  • OS
  • ClickHouse server version
  • build options of the clickhouse-cpp (specifically, what are cmake-configure-time options: BUILD_SHARED_LIBS, WITH_OPENSSL, WITH_SYSTEM_ABSEIL, WITH_SYSTEM_LZ4, WITH_SYSTEM_CITYHASH)

@rtcote
Copy link
Contributor Author

rtcote commented Sep 27, 2023

Hi @Enmk,

Info below:

  • OS: Ubuntu 20.04.6 LTS
  • Clickhouse version: 22.8.15 revision 54460
  • build options: are the defaults without options being added or modified

Insert statement from debugger with 5921 rows at the time of the crash. The data tends to have low cardinality for these tests.

"INSERT INTO databasename.tablename ( `f1`,`f2`,`f3`,`f4`,`f5`,`f6`,`f7`,`f8`,`f9`,`f10`,`f11`,`f12`,`f13`,`f14`,`f15`,`f16`,`f17`,`f18`,`f19`,`f20`,`f21`,`f22`,`f23`,`f24` ) VALUES"

Table schema

┌─name────────────────────┬─type─────┬─default_type─┬─default_expression─┬─comment─┬─codec_expression─┬─ttl_expression─┐
│ f01                     │ UInt8    │              │                    │         │ T64, LZ4         │                │
│ f02                     │ UInt16   │              │                    │         │ T64, LZ4         │                │
│ f03                     │ UInt64   │              │                    │         │ DoubleDelta, LZ4 │                │
│ f04                     │ UInt8    │              │                    │         │ T64, LZ4         │                │
│ f05                     │ UInt64   │              │                    │         │ DoubleDelta, LZ4 │                │
│ f06                     │ UInt64   │              │                    │         │ DoubleDelta, LZ4 │                │
│ f07                     │ UInt8    │              │                    │         │ T64, LZ4         │                │
│ f08                     │ UInt16   │              │                    │         │ T64, LZ4         │                │
│ f09                     │ UInt64   │              │                    │         │ DoubleDelta, LZ4 │                │
│ f10                     │ UInt8    │              │                    │         │ T64, LZ4         │                │
│ f11                     │ Int64    │              │                    │         │ T64, LZ4         │                │
│ f12                     │ UInt16   │              │                    │         │ T64, LZ4         │                │
│ f13                     │ UInt64   │              │                    │         │ T64, LZ4         │                │
│ f14                     │ Int64    │              │                    │         │ T64, LZ4         │                │
│ f15                     │ UInt16   │              │                    │         │ T64, LZ4         │                │
│ f16                     │ UInt32   │              │                    │         │ T64, LZ4         │                │
│ f17                     │ Int64    │              │                    │         │ T64, LZ4         │                │
│ f18                     │ UInt32   │              │                    │         │ T64, LZ4         │                │
│ f19                     │ Int32    │              │                    │         │ T64, LZ4         │                │
│ f20                     │ UInt32   │              │                    │         │ T64, LZ4         │                │
│ f21                     │ UInt32   │              │                    │         │ T64, LZ4         │                │
│ f22                     │ UInt32   │              │                    │         │ T64, LZ4         │                │
│ f23                     │ DateTime │              │                    │         │ DoubleDelta, LZ4 │                │
│ f24                     │ DateTime │              │                    │         │ DoubleDelta, LZ4 │                │
└─────────────────────────┴──────────┴──────────────┴────────────────────┴─────────┴──────────────────┴────────────────┘

Enmk added a commit to Enmk/clickhouse-cpp that referenced this issue Sep 29, 2023
@Enmk Enmk added bug Something isn't working priority-high Pretty important bug or issue labels Sep 30, 2023
@Enmk
Copy link
Contributor

Enmk commented Sep 30, 2023

The issue was introduced with #310, fix is in #336

@Enmk Enmk closed this as completed in #336 Sep 30, 2023
Enmk added a commit that referenced this issue Sep 30, 2023
Fixed issue #335 by making at least one connection attempt
@rtcote
Copy link
Contributor Author

rtcote commented Sep 30, 2023

Thank you @Enmk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working priority-high Pretty important bug or issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants