Skip to content

Commit 1d1da89

Browse files
committed
fix(grpc): capture loop variables in goroutine closure
Fix potential race condition by capturing loop variables 'index' and 'serviceCall' by value in the errgroup.Go() closure. Without this fix, all goroutines could reference the same loop variables, leading to concurrent access issues when processing gRPC service calls. This addresses the race condition reported in cosmo router-tests when processing recursive field resolvers with multiple levels of recursion and aliases.
1 parent 9909843 commit 1d1da89

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

v2/pkg/engine/datasource/grpc_datasource/grpc_datasource.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ func (d *DataSource) Load(ctx context.Context, input []byte, out *bytes.Buffer)
113113

114114
// make gRPC calls
115115
for index, serviceCall := range serviceCalls {
116+
// Capture loop variables to avoid closure issues
117+
index := index
118+
serviceCall := serviceCall
116119
errGrp.Go(func() error {
117120
a := astjson.Arena{}
118121
// Invoke the gRPC method - this will populate serviceCall.Output

0 commit comments

Comments
 (0)