Thread safety of confd_connect() with cdb_connect()

Our implementation utilizes a couple of threads, both of which use confd_connect() for their control and worker sockets and one of which calls cdb_connect() as part of its initialization. Both threads act as data providers with one using the callback mechanism (UG Section 6.4) and the other having the operational data stored in CDB (UG Section 6.8). One of our developers (who’s chasing what appears to be a nasty heap corruption problem in this app) is concerned (based on some valgrind results) that there might be a thread safety problem in the way confd_connect() and cdb_connect() are being used in this case (i.e., across two threads). Does anyone have some insight into this?

Thanks very much,
Dave

The general rule is: never share sockets between threads (the protocol on the sockets is generally request-reply style, and Bad Things will happen if the requests and replies from/to different threads get mixed up on a single socket - although it will typically be strange errors or hangs, not heap corruption). Additionally, you may want to note that confd_init() and confd_load_schemas() / maapi_load_schemas() are library-wide - it should be safe to have multiple threads do them, but it’s not useful, and in the case of schema loading can be a significant waste of resources. Other than that, different threads doing their confd_connect() and cdb_connect() on their own sockets in parallel should be fine.

1 Like

Since you are using valgrind, make sure you have setup ConfD for valgrind use. See this post: