[Thread]: Fix crash in ThreadStackManager during system shutdown #5700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Observe the system crash in ThreadStackManager during system shutdown.
From the backtrace, it seems the last reference on a connection was dropped without closing the connection.
(gdb) bt
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7531859 in __GI_abort () at abort.c:79
#2 0x00007ffff7c56ed2 in () at /lib/x86_64-linux-gnu/libdbus-1.so.3
#3 0x00007ffff7c79570 in _dbus_strdup () at /lib/x86_64-linux-gnu/libdbus-1.so.3
#4 0x000055555558c1ec in chip::DeviceLayer::ThreadStackManagerImpl::DBusConnectionDeleter::operator()(DBusConnection*) (this=0x5555555fae88 chip::DeviceLayer::ThreadStackManagerImpl::sInstance+8, aConnection=0x555555639860)
at ../../src/platform/Linux/ThreadStackManagerImpl.h:102
#5 0x000055555558ccd6 in std::unique_ptr<DBusConnection, chip::DeviceLayer::ThreadStackManagerImpl::DBusConnectionDeleter>::~unique_ptr()
(this=0x5555555fae88 chip::DeviceLayer::ThreadStackManagerImpl::sInstance+8, __in_chrg=) at /usr/include/c++/9/bits/unique_ptr.h:292
#6 0x000055555558e212 in chip::DeviceLayer::ThreadStackManagerImpl::~ThreadStackManagerImpl() (this=0x5555555fae80 chip::DeviceLayer::ThreadStackManagerImpl::sInstance, __in_chrg=)
at ../../src/platform/Linux/ThreadStackManagerImpl.h:95
#7 0x00007ffff7555a27 in __run_exit_handlers (status=0, listp=0x7ffff76f7718 <__exit_funcs>, run_list_atexit=run_list_atexit@entry=true, run_dtors=run_dtors@entry=true) at exit.c:108
#8 0x00007ffff7555be0 in __GI_exit (status=) at exit.c:139
#9 0x000055555556d6f2 in chip::Shell::cmd_exit(int, char**) (argc=0, argv=0x7fffffffdd18) at ../../src/lib/shell/commands.cpp:41
#10 0x000055555556ce75 in chip::Shell::Shell::ExecCommand(int, char**)Python Exception <class 'RecursionError'> maximum recursion depth exceeded while getting the str of an object:
(this=0x5555555f8140 chip::Shell::Shell::theShellRoot, argc=1, argv=0x7fffffffdd10) at ../../src/lib/shell/shell.cpp:141
#11 0x000055555556d1ab in chip::Shell::Shell::TaskLoop(void*) (arg=0x0) at ../../src/lib/shell/shell.cpp:223
#12 0x000055555556ca71 in chip::Shell::shell_task(void*) (arg=0x0) at ../../src/lib/shell/shell.h:187
#13 0x000055555556cae3 in main() () at ../../examples/shell/standalone/main.cpp:50
Summary of Changes
Close the dbus connection before freeing the dbus connection.