Skip to content
This repository was archived by the owner on Nov 7, 2025. It is now read-only.

Commit 8104a3a

Browse files
authored
Fix: fatal error: concurrent map iteration and map write (Schema.Fields) (#1466)
This PR fixes the concurrent access bug. Query execution should use a copy of the schema. The schema can be changed during that process. Common table processing was OK.
1 parent b82ffe0 commit 8104a3a

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

platform/frontend_connectors/search_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func TestSearchHandler(t *testing.T) {
272272
"user.id": {PropertyName: "user.id", InternalPropertyName: "user_id", Type: schema.QuesmaTypeKeyword},
273273
"tags": {PropertyName: "tags", InternalPropertyName: "tags", Type: schema.QuesmaTypeKeyword},
274274
"age": {PropertyName: "age", InternalPropertyName: "age", Type: schema.QuesmaTypeInteger},
275-
"host.name": {PropertyName: "host.name", InternalPropertyName: "host_name", Type: schema.QuesmaTypeObject},
275+
"host.name": {PropertyName: "host.name", InternalPropertyName: "host_name", Type: schema.QuesmaTypeKeyword},
276276
"status": {PropertyName: "status", InternalPropertyName: "status", Type: schema.QuesmaTypeKeyword},
277277
"namespace": {PropertyName: "namespace", InternalPropertyName: "namespace", Type: schema.QuesmaTypeKeyword},
278278
"namespaces": {PropertyName: "namespaces", InternalPropertyName: "namespaces", Type: schema.QuesmaTypeKeyword},

platform/frontend_connectors/search_util.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,27 @@ func (q *QueryRunner) resolveIndexesNonCommonTable(ctx context.Context, clickhou
110110
return
111111
}
112112

113-
currentSchema = resolvedSchema
113+
// Clone the resolved schema to currentSchema
114+
//
115+
// Schema can be modified during the query execution, we don't want to modify the original schema, and we don't need any concurrency issues here.
116+
//
117+
// resolveIndexesCommonTable also returns an ephemeral schema
118+
119+
currentSchema = schema.Schema{
120+
Fields: make(map[schema.FieldName]schema.Field),
121+
Aliases: make(map[schema.FieldName]schema.FieldName),
122+
ExistsInDataSource: resolvedSchema.ExistsInDataSource,
123+
DatabaseName: resolvedSchema.DatabaseName,
124+
}
125+
126+
for fieldName, field := range resolvedSchema.Fields {
127+
currentSchema.Fields[fieldName] = field
128+
}
129+
130+
for aliasName, targetFieldName := range resolvedSchema.Aliases {
131+
currentSchema.Aliases[aliasName] = targetFieldName
132+
}
133+
114134
return
115135
}
116136

0 commit comments

Comments
 (0)