(you don't have to strictly follow this form)

**Describe the bug**
The following query leads to OOM if server was built with thread sanitizer.

```sql
SELECT range(65535) FROM system.one ARRAY JOIN range(65536) AS number

std::deque<ProcessingUnit> processing_units;
    std::mutex mutex;
    std::atomic_bool emergency_stop{false};
    std::atomic_size_t collector_unit_number{0};
    std::atomic_size_t writer_unit_number{0};
    std::condition_variable collector_condvar;
    std::condition_variable writer_condvar;
    void finishAndWait();
    void onBackgroundException()
    {
        std::unique_lock<std::mutex> lock(mutex);
        if (!background_exception)
        {
            background_exception = std::current_exception();
        }
        emergency_stop = true;
        writer_condvar.notify_all();
        collector_condvar.notify_all();
    }
    void scheduleFormatterThreadForUnitWithNumber(size_t ticket_number)
    {
        pool.scheduleOrThrowOnError([this, ticket_number] { formatterThreadFunction(ticket_number); });
    }
    
    void collectorThreadFunction();
    
    void formatterThreadFunction(size_t current_unit_number);
};
}