Skip to content

C++ API aborts due to incorrect noexcept specification #131

@arghness

Description

@arghness

The C++ API can abort due to some throwing functions having a noexcept specification.

C++23 example, assuming a server is running on TCP port 9000:

#include <questdb/ingress/line_sender.hpp>

#include <print>
#include <utility>

int
main(int /*argc*/, char * /*argv*/[])
{
  try {
    auto sender = questdb::ingress::line_sender::from_conf("tcp::addr=localhost:9000;");
    sender.close();
    std::println("protocol_version={}", std::to_underlying(sender.protocol_version()));
  }
  catch (std::exception const &e) {
    std::println("Caught exception: {}", e.what());
  }

  return 0;
}

When run:

terminate called after throwing an instance of 'questdb::ingress::line_sender_error'
  what():  Sender closed.
Aborted (core dumped)

line_sender.protocol_version() and line_sender.new_buffer() are both declared as noexcept, but both call ensure_impl() which can throw. When it does, it causes the process to abort due to the incorrect exception specification.

I've made a PR with a fix at #130 which causes the exception to be caught without aborting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions