Clear connection state before stopping to avoid potential deadlocks