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.
chunk_stream_group::emplace_backstarts like this: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_backchecks 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.