Cannot set initial value a leaf item

Hi,
I have a leaf and defined a validation with.

container mydata-con {
    leaf myip {
        type inet:ipv4-address;
    }
}
tailf:annotate "/mydata-co/myip" {
    tailf:validate myipvcb {
      tailf:no-dependency;
    }
}

It works, i can set, validate and get from cdb. However, initial value is empty, I could not set an initial value when the confd starts
First tried with cdb_set_elem but could not success. Error was “item is not writable”

Try to create a new maapi_socket and run the below functions after validation register process finished.
maapi_connect
maapi_start_user_session
maapi_start_trans
maapi_set_elem
maapi_apply_trans
maapi_finish_trans(maapi_socket, th);
maapi_end_user_session

Got the logs below

TRACE Connected (maapi) to ConfD
TRACE MAAPI_START_USER_SESSION → CONFD_OK
TRACE MAAPI_START_TRANS → CONFD_OK
TRACE MAAPI_SET_ELEM /mydata-co/myip → CONFD_OK
confd Getting delta diff, no alt-name: true
devel-c Control socket request timed out daemon ‘my_module’ id 3
- Daemon my_module timed out
devel-c new_usess error {external_timeout, “”}
devel-c validate error {external_timeout, “”} for path /mydata-co/myip
TRACE MAAPI_APPLY_TRANS DEBUG external error - application timeout
→ CONFD_ERR
TRACE MAAPI_STOP_TRANS → CONFD_OK
TRACE MAAPI_END_USER_SESSION → CONFD_OK
Entiring main_loop
TRACE New user session: 17 for user:admin ctx:system → CONFD_OK
DEBUG EOF on socket to ConfD
exited with code 1

This looks like a deadlock to me; perhaps your daemon uses one thread both for validation as well as for the MAAPI stuff? When you run maapi_apply_trans, the call and your thread is blocked until all validation callbacks (and CDB subscriptions callbacks and other related callbacks) complete. So you need to run the MAAPI transaction in a separate thread, or maybe better in a separate process.

By the way: the problem you describe (provided I understand it correctly) is not really related to “initial value”, you would hit the deadlock even if the value has been already set before. Note that the initial configuration, if that’s what you are after, should be done by other means, ideally using initial XML configuration files.

1 Like