(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

break;
                assert(unit.status == READY_TO_READ);
                
                auto copy_if_unit_type = unit.type;
                
                out.write(unit.segment.data(), unit.actual_memory_size);
                if (need_flush.exchange(false) || auto_flush)
                    IOutputFormat::flush();
                ++collector_unit_number;
                {
                    
                    std::lock_guard<std::mutex> lock(mutex);
                    unit.status = READY_TO_INSERT;
                    writer_condvar.notify_all();
                }
                
                if (copy_if_unit_type == ProcessingUnitType::FINALIZE)
                {
                    break;
                }
            }
            collector_finished.set();
        }
        catch (...)
        {
            collector_finished.set();
            onBackgroundException();
        }
    }
    void ParallelFormattingOutputFormat::formatterThreadFunction(size_t current_unit_number)