From a5fb3cc0bc908b4bc823407cb0c15e41c6a881a7 Mon Sep 17 00:00:00 2001 From: prestoncraw Date: Thu, 5 Nov 2026 15:41:18 -0500 Subject: [PATCH] Clone schema in RetrieveDataAsAsyncEnumerable for concurrent callers TableOperations passes its static s_tableSchema to this method, so concurrent calls were creating rows from the same DataTable. DataTable is not thread-safe and NewRow allocates from the table's shared row storage, so concurrent queries could corrupt each other's rows. Clone the schema per call so each enumeration has its own row storage. --- src/Gemstone.Data/AdoDataConnection.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Gemstone.Data/AdoDataConnection.cs b/src/Gemstone.Data/AdoDataConnection.cs index 9eaa75d3d..c0e150ddc 100644 --- a/src/Gemstone.Data/AdoDataConnection.cs +++ b/src/Gemstone.Data/AdoDataConnection.cs @@ -1181,11 +1181,14 @@ public async IAsyncEnumerable RetrieveDataAsAsyncEnumerable(DataTable s if (!reader.HasRows) yield break; + // Clone schema so concurrent callers sharing the same schema instance do not share row storage + DataTable table = schema.Clone(); + while (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) { - DataRow row = schema.NewRow(); + DataRow row = table.NewRow(); - foreach (DataColumn col in schema.Columns) + foreach (DataColumn col in table.Columns) row[col.ColumnName] = reader[col.ColumnName]; yield return row;