Error in maapi_attach_init

Hi,

I got the following error while using maapi api.
Please let me know how to fix it.

Thanks

Error log

TRACE Connected (cdb) to ConfD
TRACE CDB_NEW_SESSION  --> CONFD_OK
TRACE Established new CDB session to ConfD
TRACE CDB_SET_NAMESPACE  --> CONFD_OK
TRACE Connected (maapi) to ConfD
TRACE MAAPI_ATTACH DEBUG item does not exist - User sess -2 doesn't exist
 --> CONFD_ERR

Test Code

{
    int rv = CONFD_ERR;
    struct sockaddr_in addr;
    int debuglevel = CONFD_DEBUG;
    int th;

    /* initialize confd library */
    confd_init("maapi_daemon", stderr, CONFD_TRACE);

    addr.sin_addr.s_addr = inet_addr("127.0.0.1");
    addr.sin_family = AF_INET;
    addr.sin_port = htons(CONFD_PORT);

#if 1
    if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0 )
        confd_fatal("Failed to open socket\n");

    cdb_connect(sock, CDB_READ_SOCKET, (struct sockaddr *)&addr, sizeof(addr));
    cdb_start_session(sock, CDB_RUNNING);
    cdb_set_namespace(sock, servers__ns);
#endif

    /* Establish a MAAPI socket */
    if (0 > (maapisock = socket(PF_INET, SOCK_STREAM, 0))) {
        printf("Failed to open socket\n");
    }

    if (CONFD_OK
        != maapi_connect(maapisock, (struct sockaddr*) &addr,
                         sizeof(struct sockaddr_in))) {
        printf("Failed to confd_connect() to confd!");
    }

    if (maapi_attach_init(maapisock, &th) < 0)
        confd_fatal("[read_conf] Failed in maapi_attach_init\n");

edit: removed my original response, mistook this API call for different one, sorry for confusion.

Your question does not state how you run the code - maybe your confd is already past phase 0 where maapi_attach_init() should be called?

Try to compare your scenario e.g. to example examples.confd/cdb_upgrade/moved_servers and the Makefile where app server_upgrade is run at appropriate time with ConfD started sequentially in phases…