Closed rbu9fe closed 8 months ago
@michalvasko, this report says that both sr_lock()
and sr_unlock()
operate on the "currently chosen datastore", not on the original one that was active in that session at the time of the lock. Can you please advice whether this is expected behavior of sysrepo?
Yes, this is expected, all the functions that use the datastore of the session use the current one, it is not stored anywhere.
Since sysrepo is behaving as expected imo sysrepo-cpp should call sr_unlock after temporarily switching to the datastore that was active when the lock was acquired in order to support the RAII principle.
Is there any progress on this? Wouldn't it make sense to track the active datastore when constructing Lock
(e.g. in m_locked_datastore
) and change the destructor to something like the following?
sr_datastore_t curr_datastore = sr_session_get_ds(session);
sr_session_switch_ds(session, m_locked_datastore);
sr_unlock(session, module, timeout);
sr_session_switch_ds(session, curr_datastore);
I was afraid that this might be tricky to do safely with RAII because these functions could fail, which would mean an exception, except that when that happens and another exception is already being handled, boom, I mean, std::terminate
. But these apparently won't fail, so, https://gerrit.cesnet.cz/c/CzechLight/sysrepo-cpp/+/6831 .
Great, thanks a lot!
The following code snipped leads to an error saying that a Yang module was not locked by this session:
Looks like the
Lock
destructor tries to callsr_unlock
for the wrong datastore. Even after session/process termination the candidate datastore remains locked in shared memory by the destroyed session.