@@ -67,6 +67,8 @@ public class EsqlExecutionInfo implements ChunkedToXContentObject, Writeable {
6767 // Updates to the Cluster occur with the updateCluster method that given the key to map transforms an
6868 // old Cluster Object to a new Cluster Object with the remapping function.
6969 public final ConcurrentMap <String , Cluster > clusterInfo ;
70+ // Is the clusterInfo map iinitialization in progress? If so, we should not try to serialize it.
71+ private transient volatile boolean clusterInfoInitializing ;
7072 // whether the user has asked for CCS metadata to be in the JSON response (the overall took will always be present)
7173 private final boolean includeCCSMetadata ;
7274
@@ -124,10 +126,8 @@ public EsqlExecutionInfo(StreamInput in) throws IOException {
124126 @ Override
125127 public void writeTo (StreamOutput out ) throws IOException {
126128 out .writeOptionalTimeValue (overallTook );
127- if (clusterInfo != null ) {
128- // .stream().toList() creates an immutable copy of the cluster info entries
129- // as today they might be still changing while serialization is happening
130- out .writeCollection (clusterInfo .values ().stream ().toList ());
129+ if (clusterInfo != null && clusterInfoInitializing == false ) {
130+ out .writeCollection (clusterInfo .values ());
131131 } else {
132132 out .writeCollection (Collections .emptyList ());
133133 }
@@ -354,6 +354,10 @@ public boolean isStopped() {
354354 return isStopped ;
355355 }
356356
357+ public void clusterInfoInitializing (boolean clusterInfoInitializing ) {
358+ this .clusterInfoInitializing = clusterInfoInitializing ;
359+ }
360+
357361 /**
358362 * Represents the search metadata about a particular cluster involved in a cross-cluster search.
359363 * The Cluster object can represent either the local cluster or a remote cluster.
0 commit comments