2021-02-23-mqtt-使用paho.mqtt.c库MQTTAsync_sendMessage发送消息时产生Segment Fault错误

本文最新地址


使用MQTTAsync_sendMessage发送消息时产生Segement Fault

在paho.mqtt.c的1.3.8版本之前(我是出现在1.3.4中),使用MQTTAsync_sendMessage发送大量数据会产生Segement Fault错误,

Seg Fault信息

第一种Segement Fault情况 SIGSEGV

测试程序出现了coredump。

./mqtt_benchmark me 1 60000
2021-2-22 1:26:57 > me0 connect success
total 1 clients are create and connected, each will publish 60000 messages!
Segmentation fault (core dumped)

gdb信息。

# gdb mqtt_benchmark core

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from mqtt_benchmark...
(No debugging symbols found in mqtt_benchmark)
[New LWP 127702]
[New LWP 127699]
[New LWP 127701]
[New LWP 127700]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./mqtt_benchmark me 1 60000'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00007fe47179af52 in MQTTAsync_addCommand () from libpaho-mqtt3as.so.1
[Current thread is 1 (Thread 0x7fe46fb4e700 (LWP 127702))]
(gdb) 
(gdb) bt
#0  0x00007fe47179af52 in MQTTAsync_addCommand () from libpaho-mqtt3as.so.1
#1  0x00007fe4717a3138 in MQTTAsync_send () from libpaho-mqtt3as.so.1
#2  0x00007fe4717a3289 in MQTTAsync_sendMessage () from libpaho-mqtt3as.so.1
#3  0x00007fe47202d789 in CWeconMqttClient::_publish(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, WMQTT_QOS_T, MQTTAsync_responseOptions*, WMQTT_MESSAGE_T, bool) () from libwmqtt.so
#4  0x00007fe47202d999 in CWeconMqttClient::publish(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, WMQTT_QOS_T, WMQTT_MESSAGE_T, bool) () from libwmqtt.so
#5  0x0000000000403a27 in threadPublish(CWeconMqttClient*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#6  0x0000000000403c31 in std::thread::_Impl<std::_Bind_simple<void (*(CWeconMqttClient*, int, char const*))(CWeconMqttClient*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >::_M_run() ()
#7  0x00007fe47165c112 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#8  0x00007fe47176f609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#9  0x00007fe471498103 in __init_misc (argc=<optimized out>, argv=0x7fe46fb4e700, envp=0x40648) at init-misc.c:33
#10 0x0000000000000000 in ?? ()
(gdb) 

mqtt库的log信息。

# ./mqtt_benchmark me 1 60000
[3]:=========================================================
[3]:                   Trace Output
[3]:Product name: Eclipse Paho Asynchronous MQTT C Client Library
[3]:Version: 1.3.4
[3]:Build level: 2021-01-27T06:55:36Z
[3]:OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
[3]:OpenSSL flags: compiler: cc -I. -I.. -I../include  -fPIC -DOPENSSL_PIC -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -m64 -DL_ENDIAN -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -Wl,-Bsymbolic-functions -Wl,-z,relro -Wa,--noexecstack -Wall -DMD32_REG_T=int -DOPENSSL_IA32_SSE2 -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_MONT5 -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DMD5_ASM -DAES_ASM -DVPAES_ASM -DBSAES_ASM -DWHIRLPOOL_ASM -DGHAS
[3]:OpenSSL build timestamp: built on: reproducible build, date unspecified
[3]:OpenSSL platform: platform: debian-amd64
[3]:OpenSSL directory: OPENSSLDIR: "/usr/lib/ssl"
[3]:/proc/version: Linux version 5.4.0-65-generic (buildd@lcy01-amd64-018) (gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)) #73-Ubuntu SMP Mon Jan 18 17:25:17 UTC 2021

[3]:=========================================================
[5]:20210222 021939.884 Error Resource deadlock avoided locking mutex
[5]:20210222 021939.884 Error Operation not permitted unlocking mutex
2021-2-22 2:19:39 > me0 connect success
total 1 clients are create and connected, each will publish 60000 messages!
[5]:20210222 021940.986 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.088 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.289 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.390 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.491 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.691 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021941.993 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.194 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.295 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.396 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.400 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.496 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.523 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.597 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.697 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.797 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.898 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021942.999 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.100 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.301 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.402 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.503 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.604 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.704 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.804 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021943.905 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021944.005 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021944.106 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021944.206 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021944.306 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
[5]:20210222 021944.507 Failed to remove heap item at file /opt/linxy_linux/applications/2021-01-27-wmqtt/vendorsrc/paho.mqtt.c-1.3.4/src/MQTTAsync.c line 1404
Segmentation fault (core dumped)

第二种Segement Fault情况 SIGABRT

后面多次测试时偶然出现了一次。

# ./mqtt_benchmark 15me 1 40000
2021-2-22 16:46:15 > 15me0 connect success
total 1 clients are create and connected, each will publish 40000 messages!
*** Error in `./mqtt_benchmark': corrupted double-linked list: 0x00007f3d6803f410 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f3d757c57e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7e6ed)[0x7f3d757cc6ed]
/lib/x86_64-linux-gnu/libc.so.6(+0x81cde)[0x7f3d757cfcde]
/lib/x86_64-linux-gnu/libc.so.6(__libc_malloc+0x54)[0x7f3d757d2184]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(_Znwm+0x18)[0x7f3d75dbbe78]
/opt/middleware/x86/lib/libwmqtt.so(_ZN16CWeconMqttClient8_publishERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_11WMQTT_QOS_TP25MQTTAsync_responseOptions15WMQTT_MESSAGE_Tb+0x26f)[0x7f3d76b677bf]
/opt/middleware/x86/lib/libwmqtt.so(_ZN16CWeconMqttClient7publishERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES7_i11WMQTT_QOS_T15WMQTT_MESSAGE_Tb+0xe9)[0x7f3d76b67999]
./mqtt_benchmark(_Z13threadPublishP16CWeconMqttClientiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0xd7)[0x403a27]
./mqtt_benchmark(_ZNSt6thread5_ImplISt12_Bind_simpleIFPFvP16CWeconMqttClientiRKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEES3_iPKcEEE6_M_runEv+0x81)[0x403c31]
/usr/lib/x86_64-linux-gnu/libstdc++.so.6(+0xb8c80)[0x7f3d75de6c80]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f3d760b76ba]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f3d7585541d]
======= Memory map: ========
00400000-00406000 r-xp 00000000 fc:00 7095656                            /opt/linxy_linux/applications/____build/mqtt_test/mqtt_benchmark
00605000-00606000 r--p 00005000 fc:00 7095656                            /opt/linxy_linux/applications/____build/mqtt_test/mqtt_benchmark
00606000-00607000 rw-p 00006000 fc:00 7095656                            /opt/linxy_linux/applications/____build/mqtt_test/mqtt_benchmark
02277000-022ca000 rw-p 00000000 00:00 0                                  [heap]
7f3d5c000000-7f3d5c021000 rw-p 00000000 00:00 0 
7f3d5c021000-7f3d60000000 ---p 00000000 00:00 0 
7f3d64000000-7f3d64021000 rw-p 00000000 00:00 0 
7f3d64021000-7f3d68000000 ---p 00000000 00:00 0 
7f3d68000000-7f3d692b1000 rw-p 00000000 00:00 0 
7f3d692b1000-7f3d6c000000 ---p 00000000 00:00 0 
7f3d6c000000-7f3d6c021000 rw-p 00000000 00:00 0 
7f3d6c021000-7f3d70000000 ---p 00000000 00:00 0 
7f3d73176000-7f3d73177000 ---p 00000000 00:00 0 
7f3d73177000-7f3d73977000 rw-p 00000000 00:00 0 
7f3d73977000-7f3d73978000 ---p 00000000 00:00 0 
7f3d73978000-7f3d74178000 rw-p 00000000 00:00 0 
7f3d74178000-7f3d74179000 ---p 00000000 00:00 0 
7f3d74179000-7f3d74979000 rw-p 00000000 00:00 0 
7f3d74979000-7f3d74b94000 r-xp 00000000 fc:00 18481571                   /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f3d74b94000-7f3d74d93000 ---p 0021b000 fc:00 18481571                   /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f3d74d93000-7f3d74daf000 r--p 0021a000 fc:00 18481571                   /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f3d74daf000-7f3d74dbb000 rw-p 00236000 fc:00 18481571                   /lib/x86_64-linux-gnu/libcrypto.so.1.0.0
7f3d74dbb000-7f3d74dbe000 rw-p 00000000 00:00 0 
7f3d74dbe000-7f3d74e1c000 r-xp 00000000 fc:00 18485882                   /lib/x86_64-linux-gnu/libssl.so.1.0.0
7f3d74e1c000-7f3d7501c000 ---p 0005e000 fc:00 18485882                   /lib/x86_64-linux-gnu/libssl.so.1.0.0
7f3d7501c000-7f3d75020000 r--p 0005e000 fc:00 18485882                   /lib/x86_64-linux-gnu/libssl.so.1.0.0
7f3d75020000-7f3d75027000 rw-p 00062000 fc:00 18485882                   /lib/x86_64-linux-gnu/libssl.so.1.0.0
7f3d75027000-7f3d7512f000 r-xp 00000000 fc:00 18481694                   /lib/x86_64-linux-gnu/libm-2.23.so
7f3d7512f000-7f3d7532e000 ---p 00108000 fc:00 18481694                   /lib/x86_64-linux-gnu/libm-2.23.so
7f3d7532e000-7f3d7532f000 r--p 00107000 fc:00 18481694                   /lib/x86_64-linux-gnu/libm-2.23.so
7f3d7532f000-7f3d75330000 rw-p 00108000 fc:00 18481694                   /lib/x86_64-linux-gnu/libm-2.23.so
7f3d75330000-7f3d75333000 r-xp 00000000 fc:00 18481667                   /lib/x86_64-linux-gnu/libdl-2.23.so
7f3d75333000-7f3d75532000 ---p 00003000 fc:00 18481667                   /lib/x86_64-linux-gnu/libdl-2.23.so
7f3d75532000-7f3d75533000 r--p 00002000 fc:00 18481667                   /lib/x86_64-linux-gnu/libdl-2.23.so
7f3d75533000-7f3d75534000 rw-p 00003000 fc:00 18481667                   /lib/x86_64-linux-gnu/libdl-2.23.so
7f3d75534000-7f3d7554d000 r-xp 00000000 fc:00 18481776                   /lib/x86_64-linux-gnu/libz.so.1.2.8
7f3d7554d000-7f3d7574c000 ---p 00019000 fc:00 18481776                   /lib/x86_64-linux-gnu/libz.so.1.2.8
7f3d7574c000-7f3d7574d000 r--p 00018000 fc:00 18481776                   /lib/x86_64-linux-gnu/libz.so.1.2.8
7f3d7574d000-7f3d7574e000 rw-p 00019000 fc:00 18481776                   /lib/x86_64-linux-gnu/libz.so.1.2.8
7f3d7574e000-7f3d7590e000 r-xp 00000000 fc:00 18481653                   /lib/x86_64-linux-gnu/libc-2.23.so
7f3d7590e000-7f3d75b0e000 ---p 001c0000 fc:00 18481653                   /lib/x86_64-linux-gnu/libc-2.23.so
7f3d75b0e000-7f3d75b12000 r--p 001c0000 fc:00 18481653                   /lib/x86_64-linux-gnu/libc-2.23.so
7f3d75b12000-7f3d75b14000 rw-p 001c4000 fc:00 18481653                   /lib/x86_64-linux-gnu/libc-2.23.so
7f3d75b14000-7f3d75b18000 rw-p 00000000 00:00 0 
7f3d75b18000-7f3d75b2e000 r-xp 00000000 fc:00 18481679                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3d75b2e000-7f3d75d2d000 ---p 00016000 fc:00 18481679                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3d75d2d000-7f3d75d2e000 rw-p 00015000 fc:00 18481679                   /lib/x86_64-linux-gnu/libgcc_s.so.1
7f3d75d2e000-7f3d75ea0000 r-xp 00000000 fc:00 266288                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3d75ea0000-7f3d760a0000 ---p 00172000 fc:00 266288                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3d760a0000-7f3d760aa000 r--p 00172000 fc:00 266288                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3d760aa000-7f3d760ac000 rw-p 0017c000 fc:00 266288                     /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.21
7f3d760ac000-7f3d760b0000 rw-p 00000000 00:00 0 
7f3d760b0000-7f3d760c8000 r-xp 00000000 fc:00 18481740                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f3d760c8000-7f3d762c7000 ---p 00018000 fc:00 18481740                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f3d762c7000-7f3d762c8000 r--p 00017000 fc:00 18481740                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f3d762c8000-7f3d762c9000 rw-p 00018000 fc:00 18481740                   /lib/x86_64-linux-gnu/libpthread-2.23.so
7f3d762c9000-7f3d762cd000 rw-p 00000000 00:00 0 
7f3d762cd000-7f3d76301000 r-xp 00000000 fc:00 5789130                    /opt/linxy_linux/applications/2021-01-27-wmqtt/middleware/x86/lib/libpaho-mqtt3as.so.1.3.4
7f3d76301000-7f3d76500000 ---p 00034000 fc:00 5789130                    /opt/linxy_linux/applications/2021-01-27-wmqtt/middleware/x86/lib/libpaho-mqtt3as.so.1.3.4
7f3d76500000-7f3d76501000 r--p 00033000 fc:00 5789130                    /opt/linxy_linux/applications/2021-01-27-wmqtt/middleware/x86/lib/libpaho-mqtt3as.so.1.3.4
7f3d76501000-7f3d76503000 rw-p 00034000 fc:00 5789130                    /opt/linxy_linux/applications/2021-01-27-wmqtt/middleware/x86/lib/libpaho-mqtt3as.so.1.3.4
7f3d76503000-7f3d7659a000 rw-p 00000000 00:00 0 
7f3d7659a000-7f3d76921000 r-xp 00000000 fc:00 23218828                   /opt/middleware/x86/lib/libcbl.so
7f3d76921000-7f3d76b21000 ---p 00387000 fc:00 23218828                   /opt/middleware/x86/lib/libcbl.so
7f3d76b21000-7f3d76b29000 r--p 00387000 fc:00 23218828                   /opt/middleware/x86/lib/libcbl.so
7f3d76b29000-7f3d76b30000 rw-p 0038f000 fc:00 23218828                   /opt/middleware/x86/lib/libcbl.so
7f3d76b30000-7f3d76b4a000 rw-p 00000000 00:00 0 
7f3d76b4a000-7f3d76b6e000 r-xp 00000000 fc:00 23221139                   /opt/middleware/x86/lib/libwmqtt.so
7f3d76b6e000-7f3d76d6d000 ---p 00024000 fc:00 23221139                   /opt/middleware/x86/lib/libwmqtt.so
7f3d76d6d000-7f3d76d6e000 r--p 00023000 fc:00 23221139                   /opt/middleware/x86/lib/libwmqtt.so
7f3d76d6e000-7f3d76d6f000 rw-p 00024000 fc:00 23221139                   /opt/middleware/x86/lib/libwmqtt.so
7f3d76d6f000-7f3d76d95000 r-xp 00000000 fc:00 18481629                   /lib/x86_64-linux-gnu/ld-2.23.so
7f3d76f7e000-7f3d76f86000 rw-p 00000000 00:00 0 
7f3d76f92000-7f3d76f94000 rw-p 00000000 00:00 0 
7f3d76f94000-7f3d76f95000 r--p 00025000 fc:00 18481629                   /lib/x86_64-linux-gnu/ld-2.23.so
7f3d76f95000-7f3d76f96000 rw-p 00026000 fc:00 18481629                   /lib/x86_64-linux-gnu/ld-2.23.so
7f3d76f96000-7f3d76f97000 rw-p 00000000 00:00 0 
7ffea41e3000-7ffea4204000 rw-p 00000000 00:00 0                          [stack]
7ffea421e000-7ffea4221000 r--p 00000000 00:00 0                          [vvar]
7ffea4221000-7ffea4223000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

gdb info.

# gdb mqtt_benchmark core

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from mqtt_benchmark...(no debugging symbols found)...done.
[New LWP 25166]
[New LWP 25163]
[New LWP 25165]
[New LWP 25164]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./mqtt_benchmark 15me 1 40000'.
Program terminated with signal SIGABRT, Aborted.
#0  __GI_raise (sig=25163) at ../sysdeps/unix/sysv/linux/raise.c:37
37      ../sysdeps/unix/sysv/linux/raise.c: No such file or directory.
[Current thread is 1 (Thread 0x7f3d73976700 (LWP 25166))]
(gdb) bt
#0  __GI_raise (sig=25163) at ../sysdeps/unix/sysv/linux/raise.c:37
#1  0x00007f3d7578502a in __GI_abort () at abort.c:87
#2  0x00007f3d762ce7b8 in ?? ()
   from /opt/linxy_linux/applications/2021-01-27-wmqtt/middleware/x86/lib/libpaho-mqtt3as.so.1
#3  0x00007f3d758deef3 in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4  0x0000000000000005 in ?? ()
#5  0x00007f3d739758a0 in ?? ()
#6  0x00007f3d68000078 in ?? ()
#7  0x00007f3d68000078 in ?? ()
#8  0x00007f3d757c55ce in __libc_message (do_abort=2, fmt=<optimized out>) at ../sysdeps/posix/libc_fatal.c:91
#9  0x00007f3d757cc6ed in malloc_printerr (ar_ptr=0x7f3d68000020, ptr=<optimized out>, 
    str=0x7f3d758dbd52 "corrupted double-linked list", action=<optimized out>) at malloc.c:5021
#10 malloc_consolidate (av=0x7f3d68000020) at malloc.c:4190
#11 0x00007f3d757cfcde in _int_malloc (av=0x7f3d68000020, bytes=1025) at malloc.c:3455
#12 0x00007f3d757d2184 in __GI___libc_malloc (bytes=25163) at malloc.c:2909
#13 0x00007f3d73975c70 in ?? ()
#14 0x00007f3d75dbbe78 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#15 0x00007f3d76b677bf in CWeconMqttClient::_publish(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, WMQTT_QOS_T, MQTTAsync_responseOptions*, WMQTT_MESSAGE_T, bool) () from /opt/middleware/x86/lib/libwmqtt.so
#16 0x00007f3d76b67999 in CWeconMqttClient::publish(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int, WMQTT_QOS_T, WMQTT_MESSAGE_T, bool) () from /opt/middleware/x86/lib/libwmqtt.so
#17 0x0000000000403a27 in threadPublish(CWeconMqttClient*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
#18 0x0000000000403c31 in std::thread::_Impl<std::_Bind_simple<void (*(CWeconMqttClient*, int, char const*))(CWeconMqttClient*, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)> >::_M_run()
    ()
#19 0x00007f3d75de6c80 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#20 0x00007f3d760b76ba in start_thread (arg=0x7f3d73976700) at pthread_create.c:333
#21 0x00007f3d7585541d in __GI___sysctl (name=0x206, nlen=25166, oldval=0x6, oldlenp=0x8, newval=0x5, newlen=0)
    at ../sysdeps/unix/sysv/linux/sysctl.c:30
#22 0x0000000000000000 in ?? ()

解决方法

升级paho.mqtt.c库到最新的版本1.3.8,在1.3.8我进行了100+次测试(每次启动若干线程发送几十K的数据),没有再出现1.3.4中出现的如上两种Seg Fault。

另外不要再连接回调中调用MQTTAsync_xxx() 连接相关方法,比如判断是否已连接MQTTAsync_isConnected(),因为和连接回调用的同个锁。。

参考

猜你喜欢

转载自blog.csdn.net/JKL852qaz/article/details/114199532