Skip to content

TLS cancel_if_not_connected unexpected behavior #236

Open
@rotrida

Description

@rotrida

Hi,

I'm using Boost 1.87, Ubuntu 24.10, clang 18.1.8, Redis 7.0.15.

Iḿ trying to identify if my connection to Redis was a success, and in order to do that I was running PING after call async_run. I noticed, though, two different behaviors, and I use or not use TLS. 127.0.0.5 is not a valid Redis server.

Running with TLS I got an error, cancel doesn't work and I see on terminal that connection and handshake process is still happening. In the end, I just would like to know if connection as a success or not:

config cfg;
   
cfg.addr.host = "127.0.0.1";
cfg.addr.port = "6379";
cfg.username = "default";
cfg.password = "mypsw";
cfg.database_index = 5;
cfg.use_ssl = true;

boost::asio::ssl::context ssl_ctx{boost::asio::ssl::context::tlsv12_client};

ssl_ctx.load_verify_file("/etc/certificates/redis_client/ca.pem");
ssl_ctx.use_certificate_file( "/etc/certificates/redis_client/client.pem", boost::asio::ssl::context::file_format::pem);
ssl_ctx.use_private_key_file( "/etc/certificates/redis_client/client.key", boost::asio::ssl::context::file_format::pem);

request req;
req.get_config().cancel_if_not_connected = true;
req.push("PING", "Hello world");

response<std::string> resp;

asio::io_context ioc;
connection conn{ioc, std::move(ssl_ctx)};

conn.async_run(cfg, {}, [](boost::system::error_code const& ec)
{
    std::cout << "async_run: " << ec.message() << std::endl;
});

conn.async_exec(req, resp, [&](auto ec, auto) {
    if (!ec)
        std::cout << "PING: " << std::get<0>(resp).value() << std::endl;
        std::cout << "CONNECTED" << std::endl;
    else
        std::cout << "Exec error: " << ec.message() << std::endl;
    conn.cancel();
});

ioc.run();

Exec error: Not connected.
(Boost.Redis) run-all-op: resolve addresses 127.0.0.1:6379
(Boost.Redis) run-all-op: connected to endpoint 127.0.0.1:6379
(Boost.Redis) Runner: SSL handshake Success
(Boost.Redis) writer-op: 143 bytes written.
(Boost.Redis) reader-op: 170 bytes read.
(Boost.Redis) hello-op: Success
(Boost.Redis) writer-op: 32 bytes written.
(Boost.Redis) reader-op: 18 bytes read.
(Boost.Redis) writer-op: 32 bytes written.
(Boost.Redis) reader-op: 18 bytes read.
(Boost.Redis) writer-op: 32 bytes written.
(Boost.Redis) reader-op: 18 bytes read.
(Boost.Redis) writer-op: 32 bytes written.
(Boost.Redis) reader-op: 18 bytes

Thanks,

Rodrigo.

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