(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::unique_lock<std::mutex> lock(mutex);
            if (background_exception && can_throw_exception)
                std::rethrow_exception(background_exception);
        }
        const auto current_unit_number = writer_unit_number % processing_units.size();
        auto & unit = processing_units[current_unit_number];
        {
            std::unique_lock<std::mutex> lock(mutex);
            writer_condvar.wait(lock,
                [&]{ return unit.status == READY_TO_INSERT || emergency_stop; });
        }
        if (emergency_stop)
            return;
        assert(unit.status == READY_TO_INSERT);
        unit.chunk = std::move(chunk);
        
        unit.segment.resize(0);
        unit.status = READY_TO_FORMAT;
        unit.type = type;
        scheduleFormatterThreadForUnitWithNumber(current_unit_number);
        ++writer_unit_number;
    }
    void ParallelFormattingOutputFormat::finishAndWait()