(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

{
        START,
        PLAIN,
        TOTALS,
        EXTREMES,
        FINALIZE
    };
    void addChunk(Chunk chunk, ProcessingUnitType type, bool can_throw_exception);
    struct ProcessingUnit
    {
        std::atomic<ProcessingUnitStatus> status{ProcessingUnitStatus::READY_TO_INSERT};
        ProcessingUnitType type{ProcessingUnitType::START};
        Chunk chunk;
        Memory<> segment;
        size_t actual_memory_size{0};
    };
    Poco::Event collector_finished{};
    std::atomic_bool need_flush{false};
    
    ThreadPool pool;
    
    ThreadFromGlobalPool collector_thread;
    std::exception_ptr background_exception = nullptr;