Giter VIP home page Giter VIP logo

nanosdk's Introduction

Discord Twitter YouTube Community Build Status

NanoSDK C Client Library for the MQTT Protocol

This repository contains the source code for the NanoSDK MQTT C client library.

This project is a wrapping of the nanomsg-NNG(https://github.com/nanomsg/nng) nanomsg known as https://github.com/nanomsg/nanomsg[libnanomsg], and adds significant new capabilities like MQTT & QUIC while retaining compatibility with the original Scalability Protocols.

NOTE: In honor of NNG & Garrett(Creator & Maintainer), they are the cornerstone of NanoSDK. We respect all his contributions to the Open-Source world. And We create this repository only for tracking Issues/Discussions and fast-paced development while the MQTT support is missing in upstream.

Introduction & Rationale

NanoSDK is an open-source project jointly developed by EMQ and NNG. NanoSDK as a repository, it is maintained independently as the NNG version of NanoMQ (https://github.com/emqx/nanomq). At present, its master branch is a special version developed and optimized for MQTT workload and maintained independently, from which we have submitted several valuable PRs and Issues for NNG. Therefore, to make NanoMQ compatible with NNG's SP protocol, we are committed to adding MQTT 3.1.1/5.0 protocol support for NNG at here. So that the two kinds of protocols(MQTT and SP) can be used together with NanoSDK. This is also in accordance with the RoadMap direction previously formulated by NanoMQ team. According to the technical goals previously formulated with the NNG project maintainer - Garrett at the jointly open-source cooperation meeting, NNG will support ZeroMQ and MQTT 3.1.1/5.0 in the future. Before this really happens, this project will be maintained independently. The internal design of NanoSDK honors the programming style of the NNG framework and is compatible with the original SP protocol of NNG. At the same time, it does not affect the other features like HTTP/Websocket/TLS.

Advantages

Compared with other popular MQTT 3.1.1 SDK, NanoSDK has the following advantages:

  1. Fully asynchronous I/O and good SMP support NanoSDK based on NNG's asynchronous I/O, we implement the Actor-like programming model in C language. And managing to distribute the computation load among multiple CPU cores averagely.
  2. High compatibility and portability Inheriting the compatibility and easy portability of NNG, NanoSDK only relies on the native POSIX standard API and is friendly to various distributions of Linux. It can be migrated to any hardware and operating system platform easily.
  3. Support multiple API styles The programming style of the NNG framework comes with a high learning cost, and users need to have a deep understanding of the concept of AIO and Context. Therefore, we also prepared a traditional callback registration mechanism for users who are accustomed to using Paho and Mosquitto SDK. This not only reduces the programming difficulty but also reserves the advantages of NNG.
  4. High throughput & Low latency In NanoMQ's test report, its performance advantages of powerful high throughput and low latency have been reflected, and the direct successor of NanoMQ - the SDK also has excellent performance. It is cost-effective in terms of resources consumption. Unlike the traditional MQTT SDK which has only 1-2 threads, NanoSDK can make full use of system hardware resources to provide higher consumption throughput. In most IoT solutions based on EMQX, the backend service’s insufficient consuming capability always results in message congestion, which has always been a problem for open source developers. Especially for QoS 1/2 messages, most SDKs reply Ack for QoS 1/2 messages synchronously. NanoSDK provides asynchronous Ack capability under the premise of ensuring the QoS message sequence and message retransmission mechanism, which greatly improves the throughput and consumption capacity of QoS 1/2.

Inherited from NNG, NanoSDK is a performant & higly portable SDK. Which enable users create client application with high throughput.

This code builds libraries which enable applications to connect to an MQTT broker to publish messages, and to subscribe to topics and receive published messages.

For MQTT broker introduction, please refer to EMQX (https://github.com/emqx/emqx)

Information About MQTT

Libraries

The NanoSDK C client comprises four variant libraries, shared or static:

  • nng/demo/mqtt- simple mqtt client
  • nng/demo/mqtt_async - asynchronous MQTT client & command-linewith SSL/TLS (MQTTAsync)
  • nng/demo/mqttv5- simple mqttv5 client with async API
  • nng/demo/quic- simple MQTT over QUIC demo (Attention: MsQUIC needs to be installed)

API Documentation

The API documentation is provided in Asciidoc format in the docs/man subdirectory The <<docs/man/nng.7.adoc#,nng(7)>> page provides a conceptual overview and links to manuals for various patterns. The <<docs/man/libnng.3.adoc#,libnng(3)>> page is a good starting point for the API reference.

In addition, many users would like to add self-defined behavior in the callback of online and offline. Therefore, we modified the callback method of connection and disconnection to allow users to perform blocking and waiting operations in the callback without affecting the MQTT connection & pradigm itself, so as to improve the flexibility of NanoSDK. However, it should be noted that this will consume the number of threads inside the NanoSDK. If the taskq thread is exhausted, it will still affect the operation of the entire client. Please use it cautiously.

Building with CMake

git clone https://github.com/emqx/NanoSDK ; cd NanoSDK
git submodule update --init --recursive 
mkdir build && cd build
cmake -G Ninja ..
ninja

To enable Debug + ASAN

cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=OFF ..

To enable MQTT over QUIC feature

cmake -G Ninja -DBUILD_SHARED_LIBS=OFF -DNNG_ENABLE_QUIC=ON ..

nanosdk's People

Contributors

alvin1221 avatar c-o-r-e avatar casaroli avatar codypiersall avatar dehorsley avatar dependabot[bot] avatar drbitboy avatar gdamore avatar hugolm84 avatar jake-ruyi avatar janjaapbos avatar jaylinyu avatar l0pital avatar liamstask avatar lilywangl avatar lkesteloot avatar mbush00 avatar mzipay avatar neachdainn avatar odywayne avatar paddor avatar phreed avatar phsilva avatar qxsoftware avatar robiwano avatar unspecd avatar urkle avatar voutilad avatar wanghaemq avatar xinyi-xs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nanosdk's Issues

mqtt_client demo

Describe the bug
SDK demo mqtt_client is not working as expected.

Actual Behavior
Broker side keep telling that the CONNECT Packet is illegal.

To Reproduce
Use demo mqtt_client to connect to NanoMQ.

** Environment Details **

  • NanoSDK/NNG version: latest
  • Operating system and version :ubt 22.04
  • Remote MQTT Broker info: NanoMQ latest

Additional context
2023-11-13 15:09:40 [33681] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33690] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33696] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33695] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33689] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33682] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33683] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0
2023-11-13 15:09:40 [33684] ERROR /home/hermann/Documents/hermannDocuments/nanomq/nng/src/sp/transport/mqtt/broker_tcp.c:327 tcptran_pipe_nego_cb: Illegal CONNECT Packet type 0

use quic example code to connect to mq over tcp fail

Describe the bug
In quic demo, connect mq over tcp fail.

Expected behavior
Connect successful.

Actual Behavior
Connect fail.

To Reproduce

** Environment Details **

  • NanoSDK/NNG version
  • Operating system and version
  • Compiler and language used
  • Shared or static library
  • Remote MQTT Broker info
    mqx config:
    listeners.tcp.default {
    bind = "0.0.0.0:1883"
    max_connections = 1024000
    }
    listeners.quic.default {
    enabled = true
    bind = "0.0.0.0:14567"
    max_connections = 1024000
    }
  • Messaging scenario

Additional context
connect mqtt-tcp://10.192.8.158:1883 fail, but connect to mqtt-tcp://10.192.8.158:14567 successful, console output:

[panzhao@localhost quic]$ ./quic_client conn mqtt-tcp://10.192.8.158:1883
QUIC Stream closed, pipe finit!
[Disconnected][CLIENT FOR QUIC]...
^C
[panzhao@localhost quic]$ ./quic_client conn mqtt-tcp://10.192.8.158:14567
[Msg Sent][CLIENT FOR QUIC]...
[Connected][CLIENT FOR QUIC]...
^C
[panzhao@localhost quic]$ ./quic_client conn mqtt-quic://10.192.8.158:14567
[Msg Sent][CLIENT FOR QUIC]...
[Connected][CLIENT FOR QUIC]...

Segmentation fault (TLS connect)

Describe the bug
Segmentation fault

To Reproduce
connect to broker via TLS.

** Environment Details **

  • NNG version: 1.6.0
  • Operating system and version: Ubuntu20.04
  • Compiler and language used: C
  • Shared or static library: static

quic demo Segmentation fault after pushlish+close

Describe the bug
Connect to broker, then publish message with qos 1, then call nng_mqtt_disconnect immediately, Segmentation fault happened.
If sleep 0.5s before nng_mqtt_disconnect, process shutdown normally.

Environment Details

  • NanoSDK/NNG version release 0.10.1

Additional context
code

call_result_t run() {

    int rv;

    debug("初始化 2024-05-06 19:31");
    if ((rv = nng_mqtt_quic_client_open_conf(m_sock, server_uri.c_str(), &config_user)) != 0) {
        std::stringstream ss;
        ss << "nng_mqtt_quic_client_open_conf return " << rv << ": " << nng_strerror(rv);
        return {false, ss.str()};
    }
    if (0 != nng_mqtt_quic_set_connect_cb(m_sock, connect_cb, nullptr) ||
            0 != nng_mqtt_quic_set_disconnect_cb(m_sock, disconnect_cb, nullptr) ||
            0 != nng_mqtt_quic_set_msg_recv_cb(m_sock, msg_recv_cb, nullptr) ||
            0 != nng_mqtt_quic_set_msg_send_cb(m_sock, msg_send_cb, nullptr)) {
        return {false, "set callback error"};
    }

    debug("连接到%s", server_uri.c_str());
    nng_msg *msg;
    rv = nng_mqtt_msg_alloc(&msg, 0);
    if (rv != 0) {
        std::stringstream ss;
        ss << "nng_mqtt_msg_alloc return " << rv << ": " << nng_strerror(rv);
        return {false, ss.str()};
    }
    nng_mqtt_msg_set_packet_type(msg, NNG_MQTT_CONNECT);
    nng_mqtt_msg_set_connect_proto_version(msg, 4);
    nng_mqtt_msg_set_connect_keep_alive(msg, 20);
    nng_mqtt_msg_set_connect_clean_session(msg, true);
    nng_mqtt_msg_set_connect_client_id(msg, client_id.c_str());
    if (username.length() > 0)
        nng_mqtt_msg_set_connect_user_name(msg, username.c_str());
    if (password.length() > 0)
        nng_mqtt_msg_set_connect_password(msg, password.c_str());

    debug("准备发送连接包,client id: %s, username: %s, password: %s", 
        client_id.c_str(), username.c_str(), password.c_str());
    rv = nng_sendmsg(*m_sock, msg, NNG_FLAG_NONBLOCK);
    debug("done");
    if (rv != 0) {
        std::stringstream ss;
        ss << "nng_sendmsg return " << rv << ": " << nng_strerror(rv);
        return {false, ss.str()};
    }


    std::cout << "input any string to continue...\n";
    std::string cmd;
    std::cin >> cmd;

    int rc;
    if ((rc = nng_mqtt_msg_alloc(&msg, 0)) != 0) {
        std::stringstream ss;
        ss << "nng_mqtt_msg_alloc return " << rc << ": " << nng_strerror(rc);
        return {false, ss.str()};
    }
    nng_mqtt_msg_set_packet_type(
            msg, NNG_MQTT_PUBLISH);
    nng_mqtt_msg_set_publish_dup(msg, 0);
    nng_mqtt_msg_set_publish_qos(msg, 1);
    nng_mqtt_msg_set_publish_retain(msg, 0);
    nng_mqtt_msg_set_publish_topic(
            msg, "/hello");
    nng_mqtt_msg_set_publish_payload(msg, (uint8_t*)"payload", 7);
    rc = nng_sendmsg(*m_sock, msg, NNG_FLAG_ALLOC);
    debug("publish nng_sendmsg return %d %s", rc, nng_strerror(rc));

    debug("*****************sleep 0.5s before disconnect");
    //std::this_thread::sleep_for(std::chrono::milliseconds(500)); // 若publish后立即关闭,程序崩溃

    debug("关闭");
    rv = nng_mqtt_disconnect(m_sock, 5, NULL); // 断网时调用阻塞15s后返回4
    //rv = nng_close(*m_sock); // 断网时调用阻塞25s后返回0
    debug("nng_close/nng_mqtt_disconnect return %d %s", rv, nng_strerror(rv));

    std::cout << "input any string to continue...\n";
    std::cin >> cmd;

    return {true};
}

core file stack

#0  ___pthread_mutex_lock (mutex=0xd) at ./nptl/pthread_mutex_lock.c:80
#1  0x00007f6c004162ad in nni_plat_mtx_lock () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#2  0x00007f6c003fd7c6 in nni_aio_finish_error () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#3  0x00007f6c0045c29b in mqtt_close_unack_msg_cb () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#4  0x00007f6c003fffc4 in nni_id_map_foreach () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#5  0x00007f6c0041cb13 in quic_mqtt_stream_close () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#6  0x00007f6c0045caeb in quic_connection_cb () from /testdir/cpp/quic/NanoSDK-0.10.1/build/libnng.so.1
#7  0x00007f6c000c3b23 in QuicConnOnShutdownComplete () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#8  0x00007f6c000cbb78 in QuicConnDrainOperations () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#9  0x00007f6c000bb453 in QuicWorkerProcessConnection () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#10 0x00007f6c000bb850 in QuicWorkerLoop () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#11 0x00007f6c000e9a13 in CxPlatRunExecutionContexts () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#12 0x00007f6c000e9c10 in CxPlatWorkerThread () from /testdir/cpp/quic/NanoSDK-0.10.1/extern/msquic/build/bin/Release/libmsquic.so.2
#13 0x00007f6bffc81ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442
#14 0x00007f6bffd13850 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

nng_recvmsg return NULL msg when receving massive QoS 2

==274546==ERROR: AddressSanitizer: heap-use-after-free on address 0x60c000179630 at pc 0x55555559c8f3 bp 0x7fffffffd3f0 sp 0x7fffffffd3e0
READ of size 8 at 0x60c000179630 thread T0
#0 0x55555559c8f2 in nni_msg_get_proto_data ../src/core/message.c:674
#1 0x5555555c2301 in nni_mqtt_msg_get_packet_type ../src/supplemental/mqtt/mqtt_msg.c:60
#2 0x5555555b8681 in nng_mqtt_msg_get_packet_type ../src/supplemental/mqtt/mqtt_public.c:42
#3 0x555555581ebb in client_subscribe ../mqtt/mqtt_client.c:180
#4 0x555555582eaf in main ../mqtt/mqtt_client.c:319
#5 0x7ffff73c1564 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28564)
#6 0x55555558122d in _start (/home/jaylin/projects/github/nng-nano/build/mqtt/mqtt_client+0x2d22d)

0x60c000179630 is located 112 bytes inside of 128-byte region [0x60c0001795c0,0x60c000179640)
freed by thread T0 here:
#0 0x7ffff768b8f7 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
#1 0x5555555aff8c in nni_free ../src/platform/posix/posix_alloc.c:33
#2 0x55555559ba6d in nni_msg_free ../src/core/message.c:461
#3 0x55555558bbd8 in nng_msg_free ../src/nng.c:1424
#4 0x555555582025 in client_subscribe ../mqtt/mqtt_client.c:192
#5 0x555555582eaf in main ../mqtt/mqtt_client.c:319
#6 0x7ffff73c1564 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28564)

previously allocated by thread T7 (nng:task) here:
#0 0x7ffff768be17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x5555555aff63 in nni_zalloc ../src/platform/posix/posix_alloc.c:26
#2 0x55555559b52b in nni_msg_alloc ../src/core/message.c:380
#3 0x5555555cda6d in mqtt_tcptran_pipe_recv_cb ../src/mqtt/transport/tcp/mqtt_tcp.c:559
#4 0x5555555aa93d in nni_taskq_thread ../src/core/taskq.c:47
#5 0x5555555abb19 in nni_thr_wrap ../src/core/thread.c:94
#6 0x5555555b2aac in nni_plat_thr_main ../src/platform/posix/posix_thread.c:266
#7 0x7ffff75be44f in start_thread nptl/pthread_create.c:473

Thread T7 (nng:task) created by T0 here:
#0 0x7ffff762f6d5 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:216
#1 0x5555555b2bdc in nni_plat_thr_init ../src/platform/posix/posix_thread.c:279
#2 0x5555555abdc2 in nni_thr_init ../src/core/thread.c:121
#3 0x5555555aac5c in nni_taskq_init ../src/core/taskq.c:92
#4 0x5555555ab7e9 in nni_taskq_sys_init ../src/core/taskq.c:251
#5 0x5555555976ca in nni_init_helper ../src/core/init.c:35
#6 0x5555555b2f30 in nni_plat_init ../src/platform/posix/posix_thread.c:422
#7 0x555555597741 in nni_init ../src/core/init.c:56
#8 0x5555555a3436 in nni_sock_open ../src/core/socket.c:630
#9 0x5555555b7cc0 in nni_proto_open ../src/sp/protocol.c:22
#10 0x5555555b796e in nng_mqtt_client_open ../src/mqtt/protocol/mqtt/mqtt_client.c:818
#11 0x555555581602 in client_connect ../mqtt/mqtt_client.c:100
#12 0x555555582a23 in main ../mqtt/mqtt_client.c:279
#13 0x7ffff73c1564 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28564)

SUMMARY: AddressSanitizer: heap-use-after-free ../src/core/message.c:674 in nni_msg_get_proto_data
Shadow bytes around the buggy address:
0x0c1880027270: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c1880027280: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x0c1880027290: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
0x0c18800272a0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c18800272b0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
=>0x0c18800272c0: fd fd fd fd fd fd[fd]fd fa fa fa fa fa fa fa fa
0x0c18800272d0: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c18800272e0: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
0x0c18800272f0: fd fd fd fd fd fd fd fd fa fa fa fa fa fa fa fa
0x0c1880027300: fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd fd
0x0c1880027310: fa fa fa fa fa fa fa fa fd fd fd fd fd fd fd fd
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==274546==ABORTING

this happens when receiving high throughput qos2 msg which is beyond client's capability.

Improving `nng_mqtt_sqlite_option` interface memory ownership

When using SQLite for message caching, the interface seems like its the end user's responsibility to call nng_mqtt_free_sqlite_opt on the allocated nng_mqtt_slite_option data structure, but looking inside the source mqtt_client.c the socket will partially free the held nng_mqtt_sqlite_option when closing. Thus it is difficult for end users to release the nng_mqtt_sqlite_option structure correctly.
It would be better to either let the end user release the structure entirely or the SDK release it as a whole.

Resource dead lock in qos_send_cb

Describe the bug
Resource deadlock avoided.

Expected behavior

Actual Behavior

To Reproduce
sending qos msg with only one aio at a high speed. then close the client abruptly.

the root reason of #26

SEGV on unknown address 0x000000000060

Describe the bug

Connecting to server ...
connect_cb: connected!
AddressSanitizer:DEADLYSIGNAL
=================================================================
==222475==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000060 (pc 0x7faaa4cb1d54 bp 0x7ffc95ec4fa0 sp 0x7ffc95ec4f98 T0)
==222475==The signal is caused by a READ memory access.
==222475==Hint: address points to the zero page.
    #0 0x7faaa4cb1d54 in pthread_mutex_lock@@GLIBC_2.2.5 (/lib64/libc.so.6+0x8fd54) (BuildId: c9f62793b9e886eb1b95077d4f26fe2b4aa1ac25)
    #1 0x4295d8 in nni_plat_mtx_lock (/home/wangha/Documents/nftp-nanosdk/build/nftp_serv+0x4295d8) (BuildId: 9ac92bbf5fbfc4b88a650e98d43cfe9f97ff7c29)
    #2 0x427765 in nni_task_busy (/home/wangha/Documents/nftp-nanosdk/build/nftp_serv+0x427765) (BuildId: 9ac92bbf5fbfc4b88a650e98d43cfe9f97ff7c29)
    #3 0x42d31c in nng_mqtt_subscribe_async (/home/wangha/Documents/nftp-nanosdk/build/nftp_serv+0x42d31c) (BuildId: 9ac92bbf5fbfc4b88a650e98d43cfe9f97ff7c29)
    #4 0x417faa in main /home/wangha/Documents/nftp-nanosdk/nftp_serv.c:338
    #5 0x7faaa4c49b89 in __libc_start_call_main (/lib64/libc.so.6+0x27b89) (BuildId: c9f62793b9e886eb1b95077d4f26fe2b4aa1ac25)
    #6 0x7faaa4c49c4a in __libc_start_main_alias_2 (/lib64/libc.so.6+0x27c4a) (BuildId: c9f62793b9e886eb1b95077d4f26fe2b4aa1ac25)
    #7 0x416994 in _start (/home/wangha/Documents/nftp-nanosdk/build/nftp_serv+0x416994) (BuildId: 9ac92bbf5fbfc4b88a650e98d43cfe9f97ff7c29)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV (/lib64/libc.so.6+0x8fd54) (BuildId: c9f62793b9e886eb1b95077d4f26fe2b4aa1ac25) in pthread_mutex_lock@@GLIBC_2.2.5
==222475==ABORTING

To Reproduce
Build with this. https://github.com/wanghaEMQ/nftp-nanosdk/tree/bug

** Environment Details **

  • NanoSDK/NNG version. latest
  • Operating system and version. fedora38
  • Compiler and language used. gcc
  • Shared or static library. shared
  • Remote MQTT Broker info. nanomq-latest
  • Messaging scenario

MQTT: publishing with QoS 1 (related to pinned issue)

Describe the bug
Hm, I think I'm now running into something similar to what is described under #228 (the pinned issue). Where it differs is that I don't get a memory leak when publishing QoS 1 messages, but a disconnection.

I'm using a loop that does nng_recvmsg() on the MQTT socket to receive, and using nng_sendmsg() on the MQTT socket to send, and everything works well until (like you mention) I set QoS to 1.

I tried to follow the advice (using dedicated AIO for publishing) by creating a nng_ctx on the socket, an associated aio and sending via nng_aio_set_msg() and nng_ctx_send(), but I see no difference. In both cases (sending via nng_sendmsg() and sending via context/nng_aio_set_msg()/nng_ctx_send()) it works fine with QoS 0 and causes a disconnection with QoS 1 ... disconnect callback is called, with the value of NNG_OPT_MQTT_DISCONNECT_REASON being 139 (which is SERVER_SHUTTING_DOWN, but the server keeps running fine). Whether I receive via a receive loop or use a receive callback does not change this behavior.

Using an explicit nng_aio_wait() after nng_aio_set_msg()/nng_ctx_send() does not help (just FYI).

Do you have an example application of how to handle publishing QoS 1 messages? The demo mqttv5_client application does not have a concurrent receive loop for the MQTT socket when in publishing mode, so it's probably not quite the same. I'm pretty sure I misunderstood the hint "Plz allocate a new aio for sending/receiving MQTT QoS 1/2 msg" from #228 in some way or misapplied it, so an example would be very instructive.

Expected behavior
I have an example of an MQTT application correctly publishing with QoS 1 and concurrent receive loop (or receive callback).

Actual Behavior
I do not have an example of an MQTT application correctly publishing with QoS 1 and concurrent receive loop (or receive callback); when trying to follow the hint from #228 and use a dedicated aio for publishing, I get disconnected with reason 139 (SERVER_SHUTTING_DOWN).

To Reproduce
Could strip down my example if needed.

Environment Details

  • NanoSDK/NNG version: NanoSDK (commit e5516c1)
  • Operating system and version: custom ARM Linux (32 bit)
  • Compiler and language used: n/a
  • Shared or static library: n/a
  • Remote MQTT Broker info: nanomq (commit 4d750bac25e01d85fb708d6d2b01d365165ab3a0)
  • Messaging scenario: n/a

Additional context
n/a

Licensing with GPL submodule?

Describe the bug

This isn't a code bug, but a question about licensing with regards to the external dependencies. NanoSDK and msquic are both licensed as MIT. wolfSSL is licensed as GPL2 (not LGPL2) though. Assuming you link wolfSSL via nng-wolfssl (which itself is GPL3), doesn't that create a conflict with the licenses, basically causing everything to have to follow the tighter restrictions of GPL2? Is it possible for NanoSDK to support SSL/TLS without needing wolfSSL?

Retain msg( tls test) can lead to nanomq error (heap use after free)

Launch nanomq with tls on, then publish a message with retain flag, and then sub will crash nanomq.

./nanomq/nanomq start --conf ../etc/nanomq.conf
mosquitto_pub -m message -p 8883 --cafile path/to/cacert.pem  --insecure -t topic -r -d
mosquitto_sub --cafile path/to/cacert.pem  -t topic -p 8883  --insecure -d
=================================================================
==99250==ERROR: AddressSanitizer: heap-use-after-free on address 0x60f00000830c at pc 0x55c8f6bb12cf bp 0x7f76145f7b90 sp 0x7f76145f7b80
WRITE of size 4 at 0x60f00000830c thread T8
    #0 0x55c8f6bb12ce in nni_atomic_dec_nv /home/lee/workspace/nanomq/nng/src/platform/posix/posix_atomic.c:120
    #1 0x55c8f6b9a7b5 in nni_msg_free /home/lee/workspace/nanomq/nng/src/core/message.c:458
    #2 0x55c8f6ecac3b in tlstran_pipe_send_cb /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:515
    #3 0x55c8f6baa70e in nni_taskq_thread /home/lee/workspace/nanomq/nng/src/core/taskq.c:50
    #4 0x55c8f6bab9ff in nni_thr_wrap /home/lee/workspace/nanomq/nng/src/core/thread.c:94
    #5 0x55c8f6bb49a6 in nni_plat_thr_main /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:266
    #6 0x7f761b575b42 in start_thread nptl/pthread_create.c:442
    #7 0x7f761b6079ff  (/lib/x86_64-linux-gnu/libc.so.6+0x1269ff)

0x60f00000830c is located 124 bytes inside of 168-byte region [0x60f000008290,0x60f000008338)
freed by thread T9 here:
    #0 0x7f761b7e1517 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:127
    #1 0x55c8f6bb0276 in nni_free /home/lee/workspace/nanomq/nng/src/platform/posix/posix_alloc.c:33
    #2 0x55c8f6b9a8a1 in nni_msg_free /home/lee/workspace/nanomq/nng/src/core/message.c:465
    #3 0x55c8f6ecac3b in tlstran_pipe_send_cb /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:515
    #4 0x55c8f6baa70e in nni_taskq_thread /home/lee/workspace/nanomq/nng/src/core/taskq.c:50
    #5 0x55c8f6bab9ff in nni_thr_wrap /home/lee/workspace/nanomq/nng/src/core/thread.c:94
    #6 0x55c8f6bb49a6 in nni_plat_thr_main /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:266
    #7 0x7f761b575b42 in start_thread nptl/pthread_create.c:442

previously allocated by thread T9 here:
    #0 0x7f761b7e1a37 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
    #1 0x55c8f6bb024d in nni_zalloc /home/lee/workspace/nanomq/nng/src/platform/posix/posix_alloc.c:26
    #2 0x55c8f6b9a36c in nni_msg_alloc /home/lee/workspace/nanomq/nng/src/core/message.c:388
    #3 0x55c8f6ecdc7a in tlstran_pipe_send_start_v4 /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:1064
    #4 0x55c8f6ed004d in tlstran_pipe_send_start /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:1404
    #5 0x55c8f6ed01a8 in tlstran_pipe_send /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:1430
    #6 0x55c8f6b9ea35 in nni_pipe_send /home/lee/workspace/nanomq/nng/src/core/pipe.c:130
    #7 0x55c8f6bd0924 in nano_ctx_send /home/lee/workspace/nanomq/nng/src/sp/protocol/mqtt/nmq_mqtt.c:428
    #8 0x55c8f6ba5ca7 in nni_ctx_send /home/lee/workspace/nanomq/nng/src/core/socket.c:1354
    #9 0x55c8f6b81713 in nng_ctx_send /home/lee/workspace/nanomq/nng/src/nng.c:401
    #10 0x55c8f6b77589 in server_cb /home/lee/workspace/nanomq/nanomq/apps/broker.c:330
    #11 0x55c8f6baaf06 in nni_task_exec /home/lee/workspace/nanomq/nng/src/core/taskq.c:144
    #12 0x55c8f6b8e2a3 in nni_aio_finish_impl /home/lee/workspace/nanomq/nng/src/core/aio.c:454
    #13 0x55c8f6b8e325 in nni_aio_finish_sync /home/lee/workspace/nanomq/nng/src/core/aio.c:469
    #14 0x55c8f6bd4885 in nano_pipe_recv_cb /home/lee/workspace/nanomq/nng/src/sp/protocol/mqtt/nmq_mqtt.c:1088
    #15 0x55c8f6baaf06 in nni_task_exec /home/lee/workspace/nanomq/nng/src/core/taskq.c:144
    #16 0x55c8f6b8e2a3 in nni_aio_finish_impl /home/lee/workspace/nanomq/nng/src/core/aio.c:454
    #17 0x55c8f6b8e325 in nni_aio_finish_sync /home/lee/workspace/nanomq/nng/src/core/aio.c:469
    #18 0x55c8f6ecc68e in tlstran_pipe_recv_cb /home/lee/workspace/nanomq/nng/src/sp/transport/mqtts/broker_tls.c:814
    #19 0x55c8f6baa70e in nni_taskq_thread /home/lee/workspace/nanomq/nng/src/core/taskq.c:50
    #20 0x55c8f6bab9ff in nni_thr_wrap /home/lee/workspace/nanomq/nng/src/core/thread.c:94
    #21 0x55c8f6bb49a6 in nni_plat_thr_main /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:266
    #22 0x7f761b575b42 in start_thread nptl/pthread_create.c:442

Thread T8 created by T0 here:
    #0 0x7f761b785685 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x55c8f6bb4ad6 in nni_plat_thr_init /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:279
    #2 0x55c8f6babcab in nni_thr_init /home/lee/workspace/nanomq/nng/src/core/thread.c:121
    #3 0x55c8f6baaa30 in nni_taskq_init /home/lee/workspace/nanomq/nng/src/core/taskq.c:95
    #4 0x55c8f6bab6c9 in nni_taskq_sys_init /home/lee/workspace/nanomq/nng/src/core/taskq.c:294
    #5 0x55c8f6b956cf in nni_init_helper /home/lee/workspace/nanomq/nng/src/core/init.c:35
    #6 0x55c8f6bb4e7b in nni_plat_init /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:422
    #7 0x55c8f6b95750 in nni_init /home/lee/workspace/nanomq/nng/src/core/init.c:58
    #8 0x55c8f6bd8c28 in nni_proto_mqtt_open /home/lee/workspace/nanomq/nng/src/sp/protocol.c:37
    #9 0x55c8f6bd5166 in nng_nmq_tcp0_open /home/lee/workspace/nanomq/nng/src/sp/protocol/mqtt/nmq_mqtt.c:1249
    #10 0x55c8f6b7b502 in broker /home/lee/workspace/nanomq/nanomq/apps/broker.c:893
    #11 0x55c8f6b7ed57 in broker_start /home/lee/workspace/nanomq/nanomq/apps/broker.c:1531
    #12 0x55c8f6b57e9b in main /home/lee/workspace/nanomq/nanomq/nanomq.c:139
    #13 0x7f761b50ad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

Thread T9 created by T0 here:
    #0 0x7f761b785685 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:216
    #1 0x55c8f6bb4ad6 in nni_plat_thr_init /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:279
    #2 0x55c8f6babcab in nni_thr_init /home/lee/workspace/nanomq/nng/src/core/thread.c:121
    #3 0x55c8f6baaa30 in nni_taskq_init /home/lee/workspace/nanomq/nng/src/core/taskq.c:95
    #4 0x55c8f6bab6c9 in nni_taskq_sys_init /home/lee/workspace/nanomq/nng/src/core/taskq.c:294
    #5 0x55c8f6b956cf in nni_init_helper /home/lee/workspace/nanomq/nng/src/core/init.c:35
    #6 0x55c8f6bb4e7b in nni_plat_init /home/lee/workspace/nanomq/nng/src/platform/posix/posix_thread.c:422
    #7 0x55c8f6b95750 in nni_init /home/lee/workspace/nanomq/nng/src/core/init.c:58
    #8 0x55c8f6bd8c28 in nni_proto_mqtt_open /home/lee/workspace/nanomq/nng/src/sp/protocol.c:37
    #9 0x55c8f6bd5166 in nng_nmq_tcp0_open /home/lee/workspace/nanomq/nng/src/sp/protocol/mqtt/nmq_mqtt.c:1249
    #10 0x55c8f6b7b502 in broker /home/lee/workspace/nanomq/nanomq/apps/broker.c:893
    #11 0x55c8f6b7ed57 in broker_start /home/lee/workspace/nanomq/nanomq/apps/broker.c:1531
    #12 0x55c8f6b57e9b in main /home/lee/workspace/nanomq/nanomq/nanomq.c:139
    #13 0x7f761b50ad8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58

SUMMARY: AddressSanitizer: heap-use-after-free /home/lee/workspace/nanomq/nng/src/platform/posix/posix_atomic.c:120 in nni_atomic_dec_nv
Shadow bytes around the buggy address:
  0x0c1e7fff9010: fa fa fa fa fa fa fd fd fd fd fd fd fd fd fd fd
  0x0c1e7fff9020: fd fd fd fd fd fd fd fd fd fd fd fa fa fa fa fa
  0x0c1e7fff9030: fa fa fa fa 00 00 00 00 00 00 00 00 00 00 00 00
  0x0c1e7fff9040: 00 00 00 00 00 00 00 00 00 fa fa fa fa fa fa fa
  0x0c1e7fff9050: fa fa fd fd fd fd fd fd fd fd fd fd fd fd fd fd
=>0x0c1e7fff9060: fd[fd]fd fd fd fd fd fa fa fa fa fa fa fa fa fa
  0x0c1e7fff9070: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1e7fff9080: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1e7fff9090: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1e7fff90a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c1e7fff90b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
  Shadow gap:              cc
==99250==ABORTING

Working build

I would like to build -- and run -- the example client.

Is there a description of the required build environment -- a CMakeLists.txt file, or a plain old fashioned Makefile ?

What are the dependencies I need to have in place? Libraries. Headers.
Very unlikely I can just gcc source_file.c and have a program that can be executed.

One of my issues with the examples I have seen ( of MQTT over QUIC ) is that they are just code snips.

And one can not run a code snip of anything non-trivial.

Examples of how to use a product should not be some kind of test of coding forensics.

panic: pthread_mutex_lock: Resource deadlock avoided

Describe the bug
Resource deadlock avoided.

Expected behavior

Actual Behavior

To Reproduce
start nanomq

nanomq broker start  --bridge ./nanomq_bridge.conf -n 128 -S 1024

emqtt_bench

emqtt_bench pub -h "192.168.23.105" -p 1883  -t "topic1/2" -s 2 -i 10 -I 10 -c 300 -q 2 -V 4 -L 500000

** Environment Details **

  • NNG version
  • Operating system and version
  • Compiler and language used
  • Shared or static library

Additional context

  • crash log:
panic: pthread_mutex_lock: Resource deadlock avoided
This message is indicative of a BUG.
Report this at https://github.com/nanomq/nanomq
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_show_backtrace+0xb8) [0x55555561cefb]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_panic+0x1ca) [0x55555561d209]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xde270) [0x555555632270]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_plat_mtx_unlock+0x1c) [0x55555563240a]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_mtx_unlock+0x1c) [0x555555629fbd]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xe2780) [0x555555636780]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xd4fa0) [0x555555628fa0]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xd620d) [0x55555562a20d]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xde9f3) [0x5555556329f3]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9590) [0x7ffff75c4590]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7ffff74ba223]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_show_backtrace+0xb8) [0x55555561cefb]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_panic+0x1ca) [0x55555561d209]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xde22a) [0x55555563222a]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_plat_mtx_lock+0x1c) [0x5555556323eb]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(nni_mtx_lock+0x1c) [0x555555629f9e]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0x12bf3f) [0x55555567ff3f]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0x12d9f0) [0x5555556819f0]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xd4fa0) [0x555555628fa0]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xd620d) [0x55555562a20d]
/home/alvin/projects/emqx/nanomq/build/nanomq/nanomq(+0xde9f3) [0x5555556329f3]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x9590) [0x7ffff75c4590]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7ffff74ba223]
  • nanomq_bridge.conf:
##====================================================================
## Configuration for MQTT Broker Bridge
##====================================================================

## Bridge address: host:port .
##
## Value: String
## Example: mqtt-tcp://127.0.0.1:1883
bridge.mqtt.address=mqtt-tcp://192.168.23.105:1885

## Protocol version of the bridge.
##
## Value: Enum
## - 5: mqttv5
## - 4: mqttv4
## - 3: mqttv3
bridge.mqtt.proto_ver=4

## Whether to enable bridge mode for mqtt bridge
##
## This option is prepared for the mqtt broker which does not
## support bridge_mode such as the mqtt-plugin of the rabbitmq
##
## Value: boolean
bridge.mqtt.bridge_mode=true

## The ClientId of a remote bridge.
##
## Placeholders:
##  ${node}: Node name
##
## Value: String
#bridge.mqtt.clientid=bridge_client

## Ping interval of a down bridge.
##
## Value: Duration
## Default: 10 seconds
bridge.mqtt.keepalive=60

## The Clean start flag of a remote bridge.
##
## Value: boolean
## Default: true
##
## NOTE: Some IoT platforms require clean_start
##       must be set to 'true'
bridge.mqtt.clean_start=true

## The username for a remote bridge.
##
## Value: String
bridge.mqtt.username=username

## The password for a remote bridge.
##
## Value: String
bridge.mqtt.password=passwd

## Topics that need to be forward to IoTHUB
##
## Value: String
## Example: topic1/#,topic2/#
bridge.mqtt.forwards=topic1/#,topic2/#

## Need to subscribe to remote broker topics
##
## Value: String
bridge.mqtt.subscription.1.topic=cmd/topic1

## Need to subscribe to remote topics QoS.
##
## Value: Number
bridge.mqtt.subscription.1.qos=1

## Need to subscribe to remote broker topics
##
## Value: String
bridge.mqtt.subscription.2.topic=cmd/topic2

## Need to subscribe to remote topics QoS.
##
## Value: Number
bridge.mqtt.subscription.2.qos=2

## parallel
## Handle a specified maximum number of outstanding requests
##
## Value: 1-infinity
bridge.mqtt.parallel=4

quic mqtt disconnect fail

Is your feature request related to a problem? Please describe.
I set keepalive=30s, and connected to mq broker over quic,
Q1. Call nng_mqtt_disconnect() or nng_close(), but online status is still online in emqx dashboard, after 20s, turn to offline, and disconnect callback called.
Q2. I didn't set auto reconnect, but the client will auto reconnect when disconnected.

Describe the solution you'd like

  1. After call nng_mqtt_disconnect() or nng_close(), please disconnect immediately.
  2. Do not auto reconnect when disconnected.
    Thanks

Describe alternatives you've considered
.

Additional context
.

Don't send SUB/UNSUB message with classical nng API

Describe the bug
sending Subscribe or unsubscribe msg with nng_sendmsg/nng_send API will cause memory leak of one SUBACK/UNSUBACK message. So just don't do this, use nng_mqtt_subscribe_async/nng_mqtt_subscribe which will deal with ack msg in its own callback. or you can use nng_send_aio and create your own callback func for suback/unsuback.

Expected behavior
no memleak when sending SUB/UNSUB message with classical nng API, however this is impossible if we wanna implement a sub callback mechanism on basis of nng aio.

nng_mqtt_client struct is weird

Is your feature request related to a problem? Please describe.
When I try to call nng_mqtt_subscribe_async/nng_mqtt_unsubscribe_async. I find I need to create a new structure nng_mqtt_client. It means that I need to manage two variables nng_socket and nng_mqtt_client. It is not friendly for users. Besides. The fields sub_aio/unsub_aio are not helpful for users.

Describe the solution you'd like
Maybe we could replace nng_mqtt_client structure with nng_socket.

Describe alternatives you've considered
.

Additional context
.

unexpected disconnect when applying massive load

$ ./emqtt_bench pub -t TESTaaa -c 100 -p 1885 -q 0 -I 1 -s 64 -V 4
connected: 91
sent(1000): total=45272, rate=45272(msg/sec)
connected: 100
sent(2001): total=144791, rate=99519(msg/sec)
sent(3001): total=244791, rate=100000(msg/sec)
sent(4001): total=344791, rate=100000(msg/sec)
sent(5000): total=444788, rate=99997(msg/sec)
$ ./nanomq/nanomq bench start sub -t TESTaaa -p 1885 -c 1
connected: 1. Topics: ["TESTaaa"]
recv: total=476, rate=476(msg/sec)
disconnected!
connected: 2. Topics: ["TESTaaa"]
recv: total=880, rate=404(msg/sec)

delete 0x00 of each string nanosdk send out.

Describe the bug
nanosdk always attach 0x00 of each string sending out.

Expected behavior
no 0x00 unless user intend to do so.

** Environment Details **

  • NanoSDK/NNG version 0.6

Memleak while receving CONNACK

Describe the bug
memleak while receving mqtt connack

Expected behavior
connack gets freed

Actual Behavior
nobody cares connack

To Reproduce
just connect

Direct leak of 128 byte(s) in 1 object(s) allocated from:
#0 0x7f3182f53e17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x55c9aefeece8 in nni_zalloc ../src/platform/posix/posix_alloc.c:26
#2 0x55c9aefda2b0 in nni_msg_alloc ../src/core/message.c:380
#3 0x55c9af00071b in nni_mqtt_msg_alloc ../src/supplemental/mqtt/mqtt_msg.c:38
#4 0x55c9af00abc3 in mqtt_tcptran_pipe_nego_cb ../src/mqtt/transport/tcp/mqtt_tcp.c:357
#5 0x55c9aefe96c2 in nni_taskq_thread ../src/core/taskq.c:47
#6 0x55c9aefea89e in nni_thr_wrap ../src/core/thread.c:94
#7 0x55c9aeff1831 in nni_plat_thr_main ../src/platform/posix/posix_thread.c:266
#8 0x7f3182e8644f in start_thread nptl/pthread_create.c:473

Indirect leak of 128 byte(s) in 1 object(s) allocated from:
#0 0x7f3182f53e17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x55c9aefeece8 in nni_zalloc ../src/platform/posix/posix_alloc.c:26
#2 0x55c9af000695 in nni_mqtt_msg_proto_data_alloc ../src/supplemental/mqtt/mqtt_msg.c:17
#3 0x55c9af000759 in nni_mqtt_msg_alloc ../src/supplemental/mqtt/mqtt_msg.c:42
#4 0x55c9af00abc3 in mqtt_tcptran_pipe_nego_cb ../src/mqtt/transport/tcp/mqtt_tcp.c:357
#5 0x55c9aefe96c2 in nni_taskq_thread ../src/core/taskq.c:47
#6 0x55c9aefea89e in nni_thr_wrap ../src/core/thread.c:94
#7 0x55c9aeff1831 in nni_plat_thr_main ../src/platform/posix/posix_thread.c:266
#8 0x7f3182e8644f in start_thread nptl/pthread_create.c:473

Can't build some of the demo projects

The CMake build step fails for the following demo projects:

  • demo/mqtt
  • demo/mqttv5
  • demo/quic_mqtt
  • demo/quic_mqttv5

I expected that the demo projects would build.
The build fails because the nng/mqtt/mqtt_client.h header can't be found.
This is caused by missing include path due to missing library alias in the demo projects CMakeLists.txt file.

QoS 1 msg : memleak when sending PUBACK

==296652==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 3456 byte(s) in 27 object(s) allocated from:
#0 0x7f3b58900e17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x564477a9fc50 in nni_zalloc ../src/platform/posix/posix_alloc.c:26
#2 0x564477a8b218 in nni_msg_alloc ../src/core/message.c:380
#3 0x564477abe03a in mqtt_tcptran_pipe_recv_cb ../src/mqtt/transport/tcp/mqtt_tcp.c:619
#4 0x564477a9a62a in nni_taskq_thread ../src/core/taskq.c:47
#5 0x564477a9b806 in nni_thr_wrap ../src/core/thread.c:94
#6 0x564477aa2799 in nni_plat_thr_main ../src/platform/posix/posix_thread.c:266
#7 0x7f3b5883344f in start_thread nptl/pthread_create.c:473

Indirect leak of 1728 byte(s) in 27 object(s) allocated from:
#0 0x7f3b58900e17 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x564477a9fc50 in nni_zalloc ../src/platform/posix/posix_alloc.c:26
#2 0x564477a89ffc in nni_chunk_grow ../src/core/message.c:151
#3 0x564477a8b268 in nni_msg_alloc ../src/core/message.c:390
#4 0x564477abe03a in mqtt_tcptran_pipe_recv_cb ../src/mqtt/transport/tcp/mqtt_tcp.c:619
#5 0x564477a9a62a in nni_taskq_thread ../src/core/taskq.c:47
#6 0x564477a9b806 in nni_thr_wrap ../src/core/thread.c:94
#7 0x564477aa2799 in nni_plat_thr_main ../src/platform/posix/posix_thread.c:266
#8 0x7f3b5883344f in start_thread nptl/pthread_create.c:473

SUMMARY: AddressSanitizer: 5184 byte(s) leaked in 54 allocation(s).

nni_mqtt_msg_get_publish_topic(),topic length =0

int msg_recv_cb(void *rmsg, void *arg)
{
nng_msg msg = static_cast<nng_msg>(rmsg);
uint32_t topicsz, payloadsz;
char *topic = (char *) nng_mqtt_msg_get_publish_topic(msg, &topicsz);
}
receive first msg can get topic,but others no topic get, topicsz=0

ex:
topic => , len : 0, payload => 9, len: 1

Tips for using `Ninja` to build NanoSDK/NanoMQ with msquic on `MacOS`

Describe the bug
Failed to use Ninja to build NanoMQ with msquic on MacOS.

../src/supplemental/quic/quic_api.c:18:10: fatal error: 'openssl/pem.h' file not found
#include "openssl/pem.h"
         ^~~~~~~~~~~~~~~
2 warnings and 1 error generated.

To Reproduce

  mkdir build 
  cd build
  cmake -G Ninja -DNNG_ENABLE_QUIC=ON ..

** Environment Details **

  • NanoSDK/NNG version : latest
  • Operating system and version: MacOS
  • Compiler and language used: C/C++
  • Shared or static library
  • Remote MQTT Broker info
  • Messaging scenario

Additional context

FAILED: CMakeFiles/nng_testing.dir/src/supplemental/quic/quic_api.c.o 
/Library/Developer/CommandLineTools/usr/bin/cc -DNNG_ENABLE_STATS -DNNG_HAVE_ARC4RANDOM=1 -DNNG_HAVE_BACKTRACE=1 -DNNG_HAVE_BUS0 -DNNG_HAVE_FLOCK=1 -DNNG_HAVE_GETPEEREID=1 -DNNG_HAVE_KQUEUE=1 -DNNG_HAVE_LANGINFO=1 -DNNG_HAVE_LOCALPEERCRED=1 -DNNG_HAVE_LOCALPEERPID=1 -DNNG_HAVE_LOCKF=1 -DNNG_HAVE_MQTT_CLIENT -DNNG_HAVE_MQTT_QUIC_CLIENT -DNNG_HAVE_MSG_CONTROL=1 -DNNG_HAVE_PAIR0 -DNNG_HAVE_PAIR1 -DNNG_HAVE_PTHREAD_ATFORK_PTHREAD=1 -DNNG_HAVE_PTHREAD_SETNAME_NP=1 -DNNG_HAVE_PUB0 -DNNG_HAVE_PULL0 -DNNG_HAVE_PUSH0 -DNNG_HAVE_REP0 -DNNG_HAVE_REQ0 -DNNG_HAVE_RESPONDENT0 -DNNG_HAVE_SEMAPHORE_PTHREAD=1 -DNNG_HAVE_STDATOMIC=1 -DNNG_HAVE_STRCASECMP=1 -DNNG_HAVE_STRLCPY=1 -DNNG_HAVE_STRNCASECMP=1 -DNNG_HAVE_STRNLEN=1 -DNNG_HAVE_SUB0 -DNNG_HAVE_SURVEYOR0 -DNNG_HAVE_UNIX_SOCKETS=1 -DNNG_HIDDEN_VISIBILITY -DNNG_MAX_TASKQ_THREADS=16 -DNNG_PLATFORM_DARWIN -DNNG_PLATFORM_POSIX -DNNG_PRIVATE -DNNG_STATIC_LIB -DNNG_SUPP_HTTP -DNNG_SUPP_QUIC -DNNG_TEST_LIB -DNNG_TRANSPORT_INPROC -DNNG_TRANSPORT_IPC -DNNG_TRANSPORT_MQTT_TCP -DNNG_TRANSPORT_MQTT_TLS -DNNG_TRANSPORT_TCP -DNNG_TRANSPORT_TLS -DNNG_TRANSPORT_WS -DNNG_TRANSPORT_WSS -DQUIC_TLS_ENGINE_FINI=nng_quic_libs_fini_msquic -DQUIC_TLS_ENGINE_INIT=nng_quic_libs_init_msquic -DSUPP_QUIC -D_GNU_SOURCE -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT -D_THREAD_SAFE -I../src -I_deps/opensslquic-build/openssl/include -I../extern/msquic/src/inc -I../src/testing -I../include -Wall -Wextra -fno-omit-frame-pointer   -O3 -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk -std=gnu99 -MD -MT CMakeFiles/nng_testing.dir/src/supplemental/quic/quic_api.c.o -MF CMakeFiles/nng_testing.dir/src/supplemental/quic/quic_api.c.o.d -o CMakeFiles/nng_testing.dir/src/supplemental/quic/quic_api.c.o -c ../src/supplemental/quic/quic_api.c
In file included from ../src/supplemental/quic/quic_api.c:11:
../extern/msquic/src/inc/msquic.h:28:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma warning(disable:4201)  // nonstandard extension used: nameless struct/union
        ^
../extern/msquic/src/inc/msquic.h:29:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma warning(disable:4214)  // nonstandard extension used: bit field types other than int
        ^
../src/supplemental/quic/quic_api.c:18:10: fatal error: 'openssl/pem.h' file not found
#include "openssl/pem.h"
         ^~~~~~~~~~~~~~~
2 warnings and 1 error generated.
[215/469] OpenSSL configure
Operating system: x86_64-apple-darwinDarwin Kernel Version 22.3.0: Mon Jan 30 20:42:11 PST 2023; root:xnu-8792.81.3~2/RELEASE_X86_64
WARNING! If you wish to build 32-bit libraries, then you have to
         invoke 'KERNEL_BITS=32 /Users/huanghuanhua/Projects/github/NanoSDK/extern/msquic/submodules/openssl/config  'enable-tls1_3' 'no-makedepend' 'no-dgram' 'no-ssl3' 'no-psk' 'no-srp' 'no-zlib' 'no-egd' 'no-idea' 'no-rc5' 'no-rc4' 'no-afalgeng' 'no-comp' 'no-cms' 'no-ct' 'no-srp' 'no-srtp' 'no-ts' 'no-gost' 'no-dso' 'no-ec2m' 'no-tls1' 'no-tls1_1' 'no-tls1_2' 'no-dtls' 'no-dtls1' 'no-dtls1_2' 'no-ssl' 'no-ssl3-method' 'no-tls1-method' 'no-tls1_1-method' 'no-tls1_2-method' 'no-dtls1-method' 'no-dtls1_2-method' 'no-siphash' 'no-whirlpool' 'no-aria' 'no-bf' 'no-blake2' 'no-sm2' 'no-sm3' 'no-sm4' 'no-camellia' 'no-cast' 'no-md4' 'no-mdc2' 'no-ocb' 'no-rc2' 'no-rmd160' 'no-scrypt' 'no-seed' 'no-weak-ssl-ciphers' 'no-shared' 'no-tests' '--openssldir=/private/etc/ssl' '--prefix=/Users/huanghuanhua/Projects/github/NanoSDK/build/_deps/opensslquic-build/openssl' '-isysroot' '/Library/Developer/CommandLineTools/SDKs/MacOSX13.1.sdk''.
Configuring OpenSSL version 1.1.1t+quic (0x1010114fL) for darwin64-x86_64-cc

SEGV on unknown address when pub illegal topic #

when I use nano_bench send illegal publish topic '#', will cause error below:

AddressSanitizer:DEADLYSIGNAL
=================================================================
==35252==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7ff618cb2766 bp 0xbebebebebebebebe sp 0x7ff60eaf11d0 T14)
==35252==The signal is caused by a READ memory access.
==35252==Hint: this fault was caused by a dereference of a high value address (see register values below).  Dissassemble the provided pc to learn which register was used.
AddressSanitizer:DEADLYSIGNAL
    #0 0x7ff618cb2766 in bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint8_t>(__sanitizer::atomic_uint8_t volatile*, __sanitizer::atomic_uint8_t::Type*, __sanitizer::atomic_uint8_t::Type, __sanitizer::memory_order) ../../../../src/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:80
    nanomq/nanomq#1 0x7ff618cb2766 in __asan::Allocator::AtomicallySetQuarantineFlagIfAllocated(__asan::AsanChunk*, void*, __sanitizer::BufferedStackTrace*) ../../../../src/libsanitizer/asan/asan_allocator.cpp:570
    nanomq/nanomq#2 0x7ff618cb2766 in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) ../../../../src/libsanitizer/asan/asan_allocator.cpp:647
    nanomq/nanomq#3 0x7ff618cb2766 in __asan::asan_free(void*, __sanitizer::BufferedStackTrace*, __asan::AllocType) ../../../../src/libsanitizer/asan/asan_allocator.cpp:883
    nanomq/nanomq#4 0x7ff618d3a186 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:128
    nanomq/nanomq#5 0x5590d55ad19e in nni_free ../nng/src/platform/posix/posix_alloc.c:33
    nanomq/nanomq#6 0x5590d557e5b3 in nng_free ../nng/src/nng.c:70
    nanomq/nanomq#7 0x5590d5546657 in free_pub_packet ../nanomq/pub_handler.c:300
    nanomq/nanomq#8 0x5590d5566fa2 in server_cb ../nanomq/apps/broker.c:443
    nanomq/nanomq#9 0x5590d55a7abe in nni_taskq_thread ../nng/src/core/taskq.c:50
    nanomq/nanomq#10 0x5590d55a8d2b in nni_thr_wrap ../nng/src/core/thread.c:94
    nanomq/nanomq#11 0x5590d55b1511 in nni_plat_thr_main ../nng/src/platform/posix/posix_thread.c:266
    nanomq/nanomq#12 0x7ff618c7158f in start_thread nptl/pthread_create.c:463
    nanomq/nanomq#13 0x7ff618b67222 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x119222)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../../../src/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:80 in bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint8_t>(__sanitizer::atomic_uint8_t volatile*, __sanitizer::atomic_uint8_t::Type*, __sanitizer::atomic_uint8_t::Type, __sanitizer::memory_order)
Thread T14 (nng:task) created by T0 here:
AddressSanitizer:DEADLYSIGNAL
AddressSanitizer:DEADLYSIGNAL
    #0 0x7ff618ce1a65 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:216
    nanomq/nanomq#1 0x5590d55b1641 in nni_plat_thr_init ../nng/src/platform/posix/posix_thread.c:279
    nanomq/nanomq#2 0x5590d55a8fd4 in nni_thr_init ../nng/src/core/thread.c:121
    nanomq/nanomq#3 0x5590d55a7ddd in nni_taskq_init ../nng/src/core/taskq.c:95
    nanomq/nanomq#4 0x5590d55a89fb in nni_taskq_sys_init ../nng/src/core/taskq.c:284
    nanomq/nanomq#5 0x5590d5594132 in nni_init_helper ../nng/src/core/init.c:35
    nanomq/nanomq#6 0x5590d55b1995 in nni_plat_init ../nng/src/platform/posix/posix_thread.c:422
    nanomq/nanomq#7 0x5590d55941b0 in nni_init ../nng/src/core/init.c:58
    nanomq/nanomq#8 0x5590d55c8810 in nni_proto_mqtt_open ../nng/src/sp/protocol.c:37
    nanomq/nanomq#9 0x5590d55c8571 in nng_nmq_tcp0_open ../nng/src/sp/protocol/mqtt/nmq_mqtt.c:1173
    nanomq/nanomq#10 0x5590d556927c in broker ../nanomq/apps/broker.c:723
    nanomq/nanomq#11 0x5590d556bb66 in broker_start ../nanomq/apps/broker.c:1154
    nanomq/nanomq#12 0x5590d5542ff2 in main ../nanomq/nanomq.c:187
    nanomq/nanomq#13 0x7ff618a76cb1 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28cb1)

==35252==ABORTING
lee@emqx-sz:~/workspace/nanomq/build$ ./nanomq/nanomq broker start
AddressSanitizer:DEADLYSIGNAL
=================================================================
==35359==ERROR: AddressSanitizer: SEGV on unknown address (pc 0x7fc539e1e766 bp 0xbebebebebebebebe sp 0x7fc5314f41d0 T11)
==35359==The signal is caused by a READ memory access.
==35359==Hint: this fault was caused by a dereference of a high value address (see register values below).  Dissassemble the provided pc to learn which register was used.
AddressSanitizer:DEADLYSIGNAL
    #0 0x7fc539e1e766 in bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint8_t>(__sanitizer::atomic_uint8_t volatile*, __sanitizer::atomic_uint8_t::Type*, __sanitizer::atomic_uint8_t::Type, __sanitizer::memory_order) ../../../../src/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:80
    nanomq/nanomq#1 0x7fc539e1e766 in __asan::Allocator::AtomicallySetQuarantineFlagIfAllocated(__asan::AsanChunk*, void*, __sanitizer::BufferedStackTrace*) ../../../../src/libsanitizer/asan/asan_allocator.cpp:570
    nanomq/nanomq#2 0x7fc539e1e766 in __asan::Allocator::Deallocate(void*, unsigned long, unsigned long, __sanitizer::BufferedStackTrace*, __asan::AllocType) ../../../../src/libsanitizer/asan/asan_allocator.cpp:647
    nanomq/nanomq#3 0x7fc539e1e766 in __asan::asan_free(void*, __sanitizer::BufferedStackTrace*, __asan::AllocType) ../../../../src/libsanitizer/asan/asan_allocator.cpp:883
    nanomq/nanomq#4 0x7fc539ea6186 in __interceptor_free ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:128
    nanomq/nanomq#5 0x56284444c19e in nni_free ../nng/src/platform/posix/posix_alloc.c:33
    nanomq/nanomq#6 0x56284441d5b3 in nng_free ../nng/src/nng.c:70
    nanomq/nanomq#7 0x5628443e5657 in free_pub_packet ../nanomq/pub_handler.c:300
    nanomq/nanomq#8 0x562844405fa2 in server_cb ../nanomq/apps/broker.c:443
    nanomq/nanomq#9 0x562844446abe in nni_taskq_thread ../nng/src/core/taskq.c:50
    nanomq/nanomq#10 0x562844447d2b in nni_thr_wrap ../nng/src/core/thread.c:94
    nanomq/nanomq#11 0x562844450511 in nni_plat_thr_main ../nng/src/platform/posix/posix_thread.c:266
AddressSanitizer:DEADLYSIGNAL
    nanomq/nanomq#12 0x7fc539ddd58f in start_thread nptl/pthread_create.c:463
    nanomq/nanomq#13 0x7fc539cd3222 in __clone (/lib/x86_64-linux-gnu/libc.so.6+0x119222)

AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV ../../../../src/libsanitizer/sanitizer_common/sanitizer_atomic_clang.h:80 in bool __sanitizer::atomic_compare_exchange_strong<__sanitizer::atomic_uint8_t>(__sanitizer::atomic_uint8_t volatile*, __sanitizer::atomic_uint8_t::Type*, __sanitizer::atomic_uint8_t::Type, __sanitizer::memory_order)
Thread T11 (nng:task) created by T0 here:
AddressSanitizer:DEADLYSIGNAL
    #0 0x7fc539e4da65 in __interceptor_pthread_create ../../../../src/libsanitizer/asan/asan_interceptors.cpp:216
    nanomq/nanomq#1 0x562844450641 in nni_plat_thr_init ../nng/src/platform/posix/posix_thread.c:279
    nanomq/nanomq#2 0x562844447fd4 in nni_thr_init ../nng/src/core/thread.c:121
    nanomq/nanomq#3 0x562844446ddd in nni_taskq_init ../nng/src/core/taskq.c:95
    nanomq/nanomq#4 0x5628444479fb in nni_taskq_sys_init ../nng/src/core/taskq.c:284
    nanomq/nanomq#5 0x562844433132 in nni_init_helper ../nng/src/core/init.c:35
    nanomq/nanomq#6 0x562844450995 in nni_plat_init ../nng/src/platform/posix/posix_thread.c:422
    nanomq/nanomq#7 0x5628444331b0 in nni_init ../nng/src/core/init.c:58
    nanomq/nanomq#8 0x562844467810 in nni_proto_mqtt_open ../nng/src/sp/protocol.c:37
    nanomq/nanomq#9 0x562844467571 in nng_nmq_tcp0_open ../nng/src/sp/protocol/mqtt/nmq_mqtt.c:1173
    nanomq/nanomq#10 0x56284440827c in broker ../nanomq/apps/broker.c:723
    nanomq/nanomq#11 0x56284440ab66 in broker_start ../nanomq/apps/broker.c:1154
    nanomq/nanomq#12 0x5628443e1ff2 in main ../nanomq/nanomq.c:187
    nanomq/nanomq#13 0x7fc539be2cb1 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x28cb1)

==35359==ABORTING

Subscribing to $SYS/brokers/connected and $SYS/brokers/disconnected

Describe the bug
Using commit e5516c1 of NanoSDK, I cannot get subscriptions to topics $SYS/brokers/connected and $SYS/brokers/disconnected of a nanomq broker to work for the mqttv5_client demo (or a custom client based upon it). Neither via explicit subscriptions to these topics nor via subscription to '#'.

Subscription reason code for these topics is successful (returning supported QoS of 2), as I interpret it.

When using clients like MQTT Explorer or MQTTX, I successfully receive messages for the $SYS/brokers/connected and $SYS/brokers/disconnected topics when another client on this broker connects/disconnects on the same broker instance (whether I subscribe directly to these topics or to '#').

When starting the other client (MQTT Explorer or MQTTX) first and then starting/killing mqttv5_client, I see connection/disconnection events for mqttv5_client, but I never seen other clients connecting when mqttv5_client is running and subscribed, so I'm assuming nanomq is correctly publishing to $SYS/brokers/connected and $SYS/brokers/disconnected.

Expected behavior
When subscribing explicitly to $SYS/brokers/connected and $SYS/brokers/disconnected, I receive the respoective messages that the broker is successfully publishing to other clients (MQTT Explorer, MQTTX).

Actual Behavior

./mqttv5_client sub mqtt-tcp://127.0.0.1:1883 0 "\$SYS/brokers/connected"
# receiving nothing when connecting/disconnecting other client


./mqttv5_client sub mqtt-tcp://127.0.0.1:1883 0 "#"
# receiving nothing when connecting/disconnecting other client
# receiving stuff published to topic 'foo' from that client

To Reproduce
See under 'Actual Behavior'

Environment Details

  • NanoSDK/NNG version: NanoSDK (commit e5516c1)
  • Operating system and version: custom ARM Linux (32 bit)
  • Compiler and language used: n/a
  • Shared or static library: n/a
  • Remote MQTT Broker info: nanomq (commit 4d750bac25e01d85fb708d6d2b01d365165ab3a0)
  • Messaging scenario: n/a

Additional context
n/a

The keepalive is ZERO if not set

Describe the bug
The keepalive is ZERO default.

Expected behavior
It should be 180/120 by default.

Actual Behavior
It should not be zero at least.

Need to connect exception backoff strategy. Need to be able to modify through configuration parameters

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

clean session function is off default

Describe the bug
The clean session function is off default. It does not comply with common sense

Expected behavior
Turn it ON by default.

Actual Behavior
It's OFF.

Building demo not succeed

When I built the project, an error happened.

I first build the nanosdk, and install it in my system.
Then build the demo mqtt.

Here is log from ninja

➜  build git:(main) ✗ ninja 
[1/2] Building C object CMakeFiles/mqtt_client.dir/mqtt_client.c.o
../mqtt_client.c: In function ‘intHandler’:
../mqtt_client.c:58:2: warning: implicit declaration of function ‘nng_closeall’; did you mean ‘nng_close’? [-Wimplicit-function-declaration]
   58 |  nng_closeall();
      |  ^~~~~~~~~~~~
      |  nng_close
[2/2] Linking C executable mqtt_client
FAILED: mqtt_client 
: && /usr/bin/cc   -rdynamic CMakeFiles/mqtt_client.dir/mqtt_client.c.o  -o mqtt_client  -lnng  -lpthread && :
/usr/bin/ld: CMakeFiles/mqtt_client.dir/mqtt_client.c.o: in function `client_connect':
mqtt_client.c:(.text+0x221): undefined reference to `nng_mqtt_client_open'
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
➜  build git:(main) ✗ pwd
/home/wangha/docu/git/NanoSDK/demo/mqtt/build

My Env. Ubuntu 20.04 x86_64

No nng_mqtt_msg_free API provided

Is your feature request related to a problem? Please describe.
I create a MQTT msg by calling nng_mqtt_msg_alloc. When I want to free it. No corresponding API was found. Should I call nng_msg_free?

Describe the solution you'd like
Please provide an API nng_mqtt_msg_free. Thanks

Describe alternatives you've considered
.

Additional context
.

Segment fault in quic_client conn

Describe the bug
when running quic_client conn xxx, segment fault is caused.

Expected behavior
quic_client conn function works

Actual Behavior
segment fault is caused

** Environment Details **

  • NanoSDK/NNG version. latest
  • Operating system and version. ubuntu20.04
  • Compiler and language used. gcc
  • Shared or static library. shared
  • Remote MQTT Broker info
  • Messaging scenario

nng_close cause seg fault

Describe the bug
actively disconnect socket trigger seg fault

Expected behavior
programe exit

Actual Behavior
client crashed

** Environment Details **
NanoSDK 0.3

Additional context
nng_close + nng_closeall cause this
0.2 is not affected

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.