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

```

elem.query_start_time = current_time_us / 1000000;
    elem.query_start_time_microseconds = current_time_us;
    elem.current_database = context.getCurrentDatabase();
    elem.query = query_for_logging;
    elem.normalized_query_hash = normalizedQueryHash<false>(query_for_logging);
    
    elem.exception_code = getCurrentExceptionCode();
    elem.exception = getCurrentExceptionMessage(false);
    elem.client_info = context.getClientInfo();
    elem.log_comment = settings.log_comment;
    if (elem.log_comment.size() > settings.max_query_size)
        elem.log_comment.resize(settings.max_query_size);
    if (settings.calculate_text_stack_trace)
        setExceptionStackTrace(elem);
    logException(context, elem);
    
    CurrentThread::finalizePerformanceCounters();
    if (settings.log_queries && elem.type >= settings.log_queries_min_type && !settings.log_queries_min_query_duration_ms.totalMilliseconds())
        if (auto query_log = context.getQueryLog())
            query_log->add(elem);
    if (auto opentelemetry_span_log = context.getOpenTelemetrySpanLog();
        context.query_trace_context.trace_id
            && opentelemetry_span_log)
    {
        OpenTelemetrySpanLogElement span;
        span.trace_id = context.query_trace_context.trace_id;
        span.span_id = context.query_trace_context.span_id;
        span.parent_span_id = context.getClientInfo().client_trace_context.span_id;
        span.operation_name = "query";
        span.start_time_us = current_time_us;