Skip to content

Deadlock when adding stream to group after packets received #314

@bmerry

Description

@bmerry

chunk_stream_group::emplace_back starts like this:

    std::lock_guard<std::mutex> lock(mutex);
    if (chunks.get_tail_chunk() != 0 || last_flush_until != 0)
    {
        throw std::runtime_error("Cannot add a stream after group has started receiving data");
    }

However, when I accidentally added readers to streams before all the streams were added, I didn't get the exception, but instead deadlocked trying to obtain the lock. There needs to be a better way to detect this condition. Possibly when the first data arrives, it can set an atomic flag, which emplace_back checks before taking the lock. This is still racy, but the whole thing is fundamentally racy anyway since it depends on the timing of the data arriving.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions