**How to reproduce**
```
for i in {1..1000}; do echo 'Hello, world!' | clickhouse-local --query "SELECT * FROM table" --structure 's String' | wc -c; done
```

This script hangs.
{
    {
        std::lock_guard lock(delayed_tasks_mutex);
        delayed_tasks.erase(task->iterator);
        task->delayed = false;
    }
    wakeup_cond.notify_all();
}
void BackgroundSchedulePool::attachToThreadGroup()
{
    std::lock_guard lock(delayed_tasks_mutex);
    if (thread_group)
    {
        
        CurrentThread::attachTo(thread_group);
    }
    else
    {
        CurrentThread::initializeQuery();
        thread_group = CurrentThread::getGroup();
    }
}
void BackgroundSchedulePool::threadFunction()