I develop a module that uses both Data Provider and CDB APIs.
Most of code for now is copied from examples, user guide and kick start guide, so I don’t see a reason to repeat it all here. But I can not get these APIs to work together.
If I initialize subscriptions first, I get:
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_HASH_DB
Connecting…
TRACE Connected (dp) to ConfD
Subscribing…
TRACE CDB_SUBSCRIBE /framerDEBUG EOF on socket to ConfD
–> CONFD_EOF
cdb_subscribe() failed
No other error messages are shown. CLI does not even show a subsystem start message.
Then I try to initialize control/worker sockets first and get this:
TRACE Connected (maapi) to ConfD
TRACE MAAPI_LOAD_ALL_NS
TRACE MAAPI_LOAD_HASH_DB
TRACE Connected (dp) to ConfD
TRACE Received daemon id 23
TRACE Connected (dp) to ConfD
TRACE Picked up old user session: 30 for user:root ctx:cli
TRACE Picked up old user session: 26 for user:system ctx:system
TRACE Picked up old user session: 25 for user:system ctx:system
TRACE Picked up old user session: 24 for user:system ctx:system
TRACE Picked up old user session: 23 for user:system ctx:system
TRACE Picked up old user session: 22 for user:system ctx:system
TRACE Picked up old user session: 21 for user:system ctx:system
TRACE Picked up old user session: 20 for user:system ctx:system
TRACE Picked up old user session: 19 for user:system ctx:system
TRACE Picked up old user session: 18 for user:system ctx:system
TRACE Picked up old user session: 17 for user:system ctx:system
TRACE Picked up old user session: 16 for user:system ctx:system
TRACE Picked up old user session: 15 for user:system ctx:system
TRACE Picked up old user session: 14 for user:system ctx:system
TRACE Picked up old user session: 13 for user:system ctx:system
TRACE Picked up old user session: 12 for user:system ctx:system
TRACE Picked up old user session: 11 for user:system ctx:system
TRACE Picked up old user session: 10 for user:system ctx:system
TRACE Picked up old user session: 9 for user:system ctx:system
TRACE Picked up old user session: 1 for user:system ctx:system
Connecting…
TRACE Connected (dp) to ConfD
Subscribing…
TRACE CDB_SUBSCRIBE /framer
And deadlock here. cdb_subscribe() just does not return control ever.
I see a subsystem start message in CLI, but no interaction with this subsystem is possible, even operational data does not work.
If I comment out all subscription stuff from my code, all works fine.
I found this topic, but it seems to be related to some older version of confd (no daemon context in cdb_connect() etc) and does not solve my issue.
Perhaps you are trying to use the same socket for your data providers and subscribers? You need one socket per thread. No sharing of sockets between threads.
From ConfD UG chapter The Protocol and a Library Threads Discussion:
ConfD API functions are thread-safe as such, but multiple threads using them with the same socket will have unpredictable results, just as multiple threads using the read() and write() system calls on the same file descriptor in general will. In the ConfD case, one thread may end up getting the response to a request from another, or even a part of that response, which will result in errors that can be very difficult to debug.
I believe your issues are copy paste errors in both cases,
TRACE CDB_SUBSCRIBE /framerDEBUG EOF on socket to ConfD
–> CONFD_EOF
The socket you did a cdb_subscribe() on was likely connected as a DP worker socket using confd_connect(.., my_subscriber_socket, WORKER_SOCKET, ..., ...)
TRACE CDB_SUBSCRIBE /framer
And deadlock here. cdb_subscribe() just does not return control ever.
The socket you did a cdb_subscribe() on was likely connected as a DP control socket using confd_connect(..., my_subscriber_socket, CONTROL_SOCKET, ..., ...)
You need to connect your subscriber socket using cdb_connect(my_subscriber_socket, CDB_SUBSCRIPTION_SOCKET, ... , ...)