[libvirt-users] error : virHashForEach:597 : Hash operation not allowed during iteration

Vincent Bernat bernat at luffy.cx
Wed Apr 4 18:38:12 UTC 2018


 ❦  4 avril 2018 17:00 +0200, Vincent Bernat <bernat at luffy.cx> :

>>> You can do that locally, but as a patch it's very unlikely to be
>>> accepted upstream because we've introduced RW locks to be able to access
>>> domain list from multiple threads.
>>
>> Looking a bit more, the whole "iterating" bit is currently
>> unsafe. First, it is racy since it's "check then take". Two threads may
>> check the value is false and start iterating both. Moreover, at some
>> places, it is not set, for example in virHashAddOrUpdateEntry(). So, it
>> would be possible to call this function and during the update to iterate
>> over the hash. This seems to be prevented only by callers using RW
>> lock. So, it seems we can just remove this "iterating" bool and just
>> check all users of these functions are using the appropriate lock.
>
> My bad, I didn't see the use of table->current...

It seems it can also go away if caller correctly use a RW lock. I am
currently testing the attached patch on a few servers (patch for master,
but applied on our 3.6 version). After checking many locations, I came
to conclusion that locks are used correctly.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-util-don-t-check-for-parallel-iteration-in-hash-rela.patch
Type: text/x-diff
Size: 7773 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20180404/e5cf84c3/attachment.bin>
-------------- next part --------------

-- 
Use library functions.
            - The Elements of Programming Style (Kernighan & Plauger)


More information about the libvirt-users mailing list