**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_exec(exec_mutex);
    std::lock_guard lock_schedule(schedule_mutex);
    if (deactivated)
        return;
    deactivated = true;
    scheduled = false;
    if (delayed)
        pool.cancelDelayedTask(shared_from_this(), lock_schedule);
}
void BackgroundSchedulePoolTaskInfo::activate()
{
    std::lock_guard lock(schedule_mutex);
    deactivated = false;
}
bool BackgroundSchedulePoolTaskInfo::activateAndSchedule()
{
    std::lock_guard lock(schedule_mutex);
    deactivated = false;
    if (scheduled)
        return false;
    scheduleImpl(lock);
    return true;
}
void BackgroundSchedulePoolTaskInfo::execute()