How to reproduce:

```sql
EXPLAIN SYNTAX
SELECT x
FROM 
(
    SELECT 1 AS x
    UNION DISTINCT
    SELECT 1
)

Query id: e777bc02-5d1b-4d49-ba89-4ebe31172387


Exception on client:
Code: 32. DB::Exception: Attempt to read after eof: while receiving packet from localhost:9000

```

bool may_have_tail;
    if (istr.buffer().end() - istr.position() > static_cast<ssize_t>(max_query_size))
    {
        
        begin = istr.position();
        end = istr.buffer().end();
        istr.position() += end - begin;
        
        
        may_have_tail = true;
    }
    else
    {
        
        WriteBufferFromVector<PODArray<char>> out(parse_buf);
        LimitReadBuffer limit(istr, max_query_size + 1, false);
        copyData(limit, out);
        out.finalize();
        begin = parse_buf.data();
        end = begin + parse_buf.size();
        
        may_have_tail = !istr.eof();
    }
    ASTPtr ast;
    BlockIO streams;
    std::tie(ast, streams) = executeQueryImpl(begin, end, context, false, QueryProcessingStage::Complete, may_have_tail, &istr);
    auto & pipeline = streams.pipeline;
    try
    {
        if (streams.out)