# Start maapi user session failed:operation in wrong state

**URL:** <https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647>\
**Category:** CDB and CDB API\
**Created:** [November 14, 2017, 10:25am UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647 "2017-11-14T10:25:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bibin](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Bibin](https://dmap-community.ductus.global/u/Bibin)\
**Post date:** [November 14, 2017, 10:25am UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647/1 "2017-11-14T10:25:58Z")

</div>

Hi,

I am facing a new issue it was not seen before.

Nov 14 02:12:26: %LOG-6-PRI\_ACTIVE: Nov 14 02:12:26: %NETCONF-YANG-3-ERR: cmns Start maapi user session failed:operation in wrong state(17),errmsg:No usersessions if no startphase2

Is failing …

After enabling CONFD\_TRACE i can see this

[13-11-2017 12:32:49] CONFD:getConfig called  
[13-11-2017 12:32:49] Entered : maapi\_conn  
TRACE MAAPI\_START\_USER\_SESSION DEBUG operation in wrong state - No usersessions if no startphase2  
–\> CONFD\_ERR

Code used :

static const char \*groups[] = {“admin”};

```
    if(maapi_start_user_session(eb_maapi_sock, "admin", "maapi", groups, 1,
                            &ip, CONFD_PROTO_TCP) != CONFD_OK )
  {
    DBG_WTF("CONFD:Failed to maapi_start_user_session\n");
    return FAILURE_VAL;
  }

```

Can you please suggest any thing i need to add or change to overcome this issue.

Regards,  
Bibin

---

<div class="post-metadata">

**Author:** ![nabil](https://avatars.discourse-cdn.com/v4/letter/n/e79b87/32.png) [@nabil](https://dmap-community.ductus.global/u/nabil)\
**Post date:** [November 14, 2017, 12:54pm UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647/2 "2017-11-14T12:54:37Z")

</div>

It looks like ConfD hasn’t completely started, in phase 2.

Run: “ConfD —status” to check.

---

<div class="post-metadata">

**Author:** ![cohult](https://yyz2.discourse-cdn.com/flex010/user_avatar/dmap-community.ductus.global/cohult/32/221_2.png) [@cohult](https://dmap-community.ductus.global/u/cohult)\
**Post date:** [November 14, 2017, 12:58pm UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647/3 "2017-11-14T12:58:28Z")

</div>

Hi,

As Nabil writes, ConfD is not up and running yet. You can either time your application to connect to ConfD earlier than start-phase 2, using maapi\_attach\_init() or wait until ConfD has reached start-phase 2 using maapi\_wait\_start().

For documentation on ConfD start-phases:

- ConfD UG / man pages under “COMMUNICATING WITH CONFD”
- confd\_lib\_maapi man page, maapi\_attach\_init() maapi\_start\_phase() and maapi\_wait\_start()

---

<div class="post-metadata">

**Author:** ![Bibin](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Bibin](https://dmap-community.ductus.global/u/Bibin)\
**Post date:** [November 16, 2017, 10:03am UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647/4 "2017-11-16T10:03:51Z")

</div>

Hi,

Thanks for the response…

Should i use all of them maapi\_attach\_init() maapi\_start\_phase() and maapi\_wait\_start()

Or i can use maapi\_wait\_start() itself …

Regards,  
Bibin

---

<div class="post-metadata">

**Author:** ![Bibin](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Bibin](https://dmap-community.ductus.global/u/Bibin)\
**Post date:** [November 16, 2017, 10:23am UTC](https://dmap-community.ductus.global/t/start-maapi-user-session-failed-operation-in-wrong-state/1647/5 "2017-11-16T10:23:36Z")

</div>

Hi,

One more doubt … as we have implemented rule-list and added the our module(.yang) under some group,

So do i need to change this code snippet

if(maapi\_start\_user\_session(eb\_maapi\_sock, “admin”, “maapi”, groups, 1,  
&ip, CONFD\_PROTO\_TCP) != CONFD\_OK )  
{  
DBG\_WTF(“CONFD:Failed to maapi\_start\_user\_session\n”);  
return FAILURE\_VAL;  
}

Eg: in my rule-list it is group is [ApplicationAccess] then do i need to change in int maapi\_start\_user\_session(int sock, const char \*username, const char \*context, const char \*\*groups, int numgroups, const struct confd\_ip \*src\_addr, enum confd\_proto prot);  
to that group(ApplicationAccess)…??

Regards,  
Bibin
