Skip to content

[Bug] Publisher put spent too much time to return when declare a publisher and a queryable in one session #523

@aipiano

Description

@aipiano

Describe the bug

I use zenoh-cpp.
I declare a publisher and a queryable in one session.
The 'put' method of publisher can return immediately in the first few seconds. Then it may block the thread about 5 seconds occasionally even no any subscriber at all.

If no queryable is declared, the problem solved.

To reproduce

int main(int argc, char* argv[])
{
    auto session
        = std::make_unique<zenoh::Session>(zenoh::Config::create_default());

    auto params_queryable_options
        = zenoh::Session::QueryableOptions::create_default();

    auto qable = session->declare_queryable(
        "nmx/queryable/key", [](const zenoh::Query& query) {}, []() {},
        std::move(params_queryable_options));

    zenoh::Session::PublisherOptions pub_options
        = zenoh::Session::PublisherOptions::create_default();
    auto publisher = session->declare_publisher(
        "nmx/publisher/key", std::move(pub_options));

    while (true) {
        std::this_thread::sleep_for(std::chrono::milliseconds(33));

        std::vector<uint8_t> buffer(256, 0);

        zenoh::Bytes::Writer zenoh_writer;
        zenoh_writer.append(std::move(buffer));

        auto bytes = std::move(zenoh_writer).finish();

        auto options = zenoh::Publisher::PutOptions::create_default();
        options.encoding = zenoh::Encoding::Predefined::zenoh_bytes();
        options.timestamp = session->new_timestamp();

        auto start = std::chrono::high_resolution_clock::now();

        publisher.put(std::move(bytes), std::move(options));

        auto stop = std::chrono::high_resolution_clock::now();

        std::cout << "Publish time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(
                         stop - start)
                         .count()
                  << std::endl;
    }

    return 0;
}

System info

Platform: x86_64
System: Ubuntu 22.04
Zenoh-cpp: 1.1.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions