This MR fixes several race condition segfaults that happens when starting and stopping a client multiple times.