Skip to content

Potential race condition in DescriptorPool::freeDescriptorSet #1745

Description

@dariuszwas

Describe the bug
I believe following code contains a race condition.
https://github.com/vsg-dev/VulkanSceneGraph/blob/master/src/vsg/vk/DescriptorPool.cpp#L139

    {
        std::scoped_lock<std::mutex> lock(mutex);
        _recyclingList.push_back(dsi);
        ++_availableDescriptorSet;
        accumulateBindings(_recycledDescriptorPoolSizes, dsi->_descriptorSetLayout, +1);
    }
    dsi->_descriptorPool = {};

dsi->_descriptorPool can be overwritten by thread_2 inside allocateDescriptorSet() while thread_1 has left the mutex but didn't yet perform:
dsi->_descriptorPool = {};

To Reproduce
I got one crash. Reproducing this is not easy.

Possible solution

    auto keepAlive = dsi->_descriptorPool;
    {
        std::scoped_lock<std::mutex> lock(mutex);
        _recyclingList.push_back(dsi);
        ++_availableDescriptorSet;
        accumulateBindings(_recycledDescriptorPoolSizes, dsi->_descriptorSetLayout, +1);
        dsi->_descriptorPool = {};
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions