eclipse / paho.mqtt-sn.embedded-c

Paho C MQTT-SN gateway and libraries for embedded systems. Paho is an Eclipse IoT project.
https://eclipse.org/paho
Other
314 stars 179 forks source link

SN gateway terminates on receiving disconnect requests from client #213

Closed mailych closed 3 years ago

mailych commented 3 years ago

SN gateway crashes (Segmentation fault) on receiving disconnect requests from client. It doesn't always happen.

Issue can be reproduced by running MQTT-SNPub binary multiple times. This is part of package.

Below is last lines when issue happens

Issue can 20200911 062703.443 PUBLISH ===> ClientPUB 30 26 00 0C 74 79 34 74 77 2F 74 6F 70 69 63 32 70 75 62 6C 69 73 68 20 22 74 79 34 74 77 2F 74 6F 70 69 63 32 22 20 0A 20200911 062704.950 DISCONNECT <--- ClientPUB 02 18 20200911 062704.950 DISCONNECT ---> ClientPUB 02 18 20200911 062704.950 DISCONNECT ===> ClientPUB E0 00 Segmentation fault ~/projects$

mailych commented 3 years ago

I investigated this further. I build a debug version and with optimization 2 of MQTT-SNGateway

Ran it with gdb. Below is the back trace I have received

20200910 181731.046 DISCONNECT <--- x 02 18 20200910 181731.047 DISCONNECT ===> x E0 00 20200910 181731.047 DISCONNECT ---> x 02 18

[New LWP 20833] [New LWP 20834] [New LWP 20835] [New LWP 20836] [New LWP 20838] [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-SNGateway'. Program terminated with signal SIGSEGV, Segmentation fault.

0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62

62 ../sysdeps/x86_64/multiarch/strlen-avx2.S: No such file or directory. [Current thread is 1 (Thread 0x7f9da83fe700 (LWP 20837))] (gdb) bt

0 __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:62

1 0x00007f9daa201563 in _IO_vfprintf_internal (s=s@entry=0x7f9da83fdb10,

format=format@entry=0x55f690da4140 "%s   \033[0m\033[0;33m%-18s%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n", ap=ap@entry=0x7f9da83fdc50)
at vfprintf.c:1643

2 0x00007f9daa2d617b in ___vsprintf_chk (

s=0x55f690fb3284 <gateway+164> "20200909 111125.044   \033[0m\033[0;33mRESERVED          ===>  \033[0m\033[0;37mClientPUB", ' ' <repeats 26 times>, "\033[0m\033[0;34m E0 00\033[0m\033[0;37m\n", flags=1, slen=18446744073709551615,
format=0x55f690da4140 "%s   \033[0m\033[0;33m%-18s%-6s\033[0m\033[0;37m%-34.32s \033[0m\033[0;34m%s\033[0m\033[0;37m\n", args=0x7f9da83fdc50) at vsprintf_chk.c:82

3 0x000055f690d84925 in MQTTSNGW::Process::putLog(char const*, ...) ()

4 0x000055f690d7d71f in MQTTSNGW::BrokerRecvTask::run() ()

5 0x000055f690d7d869 in MQTTSNGW::BrokerRecvTask::EXECRUN() ()

6 0x000055f690d92226 in MQTTSNGW::Thread::_run(void*) ()

7 0x00007f9dab49d6db in start_thread (arg=0x7f9da83fe700) at pthread_create.c:463

8 0x00007f9daa2c5a3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

(gdb)

mailych commented 3 years ago

Sorry, Please ignore this issue. The crash was caused because of local change in the code.